| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | VAC++ and it`s compiled regular exp |
Hello Mike!
Friday August 09 1996 19:16, Mike Burgett wrote to All:
MB> struct TestRegEx *temp;
MB> count = 0;
MB> while(temp = testmask[count++])
MB> {
MB> if (regexec(&(testmask[count]->expr), checkstring, 0, 0) == 0);
MB> break
MB> }
I'm hoping you typed this in by hand . Unless I'm missing
something in your code, you're always skipping the first regex_t. You're
also missing the last parameter of the regexec() call.
MB> if I feed it two mask strings, zee* and ab* (in that order) and send
MB> test01.dat, zee000.dat, and test02.dat through the regexec() call, I get a
MB> match on the second mask for the first string, and a match on the first
MB> mask for the second string, and then a match on the second mask for the
MB> third string.
MB> playing with the mask string, it seems that it doesn't matter what I set it
MB> to, j* matches test01.dat and test02.dat as well.....
Ok, you really need to read up on regular expressions . The '*'
modifier means to match 0 or more of the preceeding character. Hence,
'zee*' will match 'ze' and 'zeeeeee'. 'ab*' is matching the 'a' in 'dat'.
'j*' will match anything.
You probably want 'zee.*' and 'ab.*'. Here is a sample util I just whipped up.
-- CUT -------- Begin test.cpp -------- CUT --
#include
#include
const char *searchStrings[] = {"zee.*", "ab.*"};
const char *testData[] = {"test01.dat", "zee000.dat",
"test02.dat"};
int main() {
regex_t regularExpressions[2];
int i = 0;
int j = 0;
for (i=0; i<2; i++) {
regcomp(®ularExpressions[i], searchStrings[i], REG_EXTENDED |
REG_ICASE | REG_NOSUB);
}
for (j=0; j<3; j++) {
for (i=0; i<2; i++) {
if (regexec(®ularExpressions[i], testData[j], 0, 0, 0) == 0) {
cout << searchStrings[i] << " matches "
<< testData[j] << endl;
}
}
}
for (i=0; i<2; i++) {
regfree(®ularExpressions[i]);
}
return 0;
}
-- CUT --------- End test.cpp --------- CUT --
Doug
--- GoldED/2 3.00.Alpha1+
* Origin: Realm of the Dragons - `Where thy mind hath no limits' (1:250/516)SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934 SEEN-BY: 711/955 712/407 515 624 628 713/888 800/1 @PATH: 250/516 101 99 3615/50 396/1 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.