[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
regex problem
From: |
Adam T. Bowen |
Subject: |
regex problem |
Date: |
Tue, 29 Oct 2002 15:59:16 +0000 (GMT) |
Hi,
I am having some difficulty with the regex functions (regexec,
regcomp) in libc version 2.2.93 compiling with gcc version 3.2. The code
is as follows :
#include <sys/types.h>
#include <regex.h>
int main(int argc, char **argv)
{
regex_t RE;
regmatch_t RM[10];
char *Test_String="testing\n";
int Pos=0;
regcomp(&RE, "(t[^z]+z)",REG_EXTENDED);
while(regexec(&RE, &Test_String[Pos], (size_t)1, RM, 0) == 0)
{
printf("Match from %ld to %ld\n",Pos+RM[0].rm_so,Pos+RM[0].rm_eo-1);
Pos+=RM[0].rm_eo;
}
return 0;
}
The output of this is :
Match from 0 to 7
If the regular expression is changed to "(t[^r]+z)" 'r' being another
character that isn't in the string, it outputs nothing, as expected.
Also, if I change the string to "testing" (the trailing newline removed)
and use it with the original regular expression "(t[^z]+z)" it also
outputs nothing, as expected. The same code using libc version 2.2.4
works correctly.
While I'm on, could I ask if anyone has any opinions of what is
better to use - as concerns speed, portability and development - gnu regex
functions or posix regex functions?
Thank you for your time.
Adam Bowen
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- regex problem,
Adam T. Bowen <=