03-29-04 04:38 AM
Hello:
I am trying to use the string OR in my regex pattern to allow multiple
possibilities for a string, but it is failing.
Take, for example, the string
"adsl-68-72-170-142.dsl.chcgil.ameritech.net"
When I apply this regex pattern: "\\.ameritech\\.net$"
I get a match
But, when I apply this regex pattern: "\\.(ameritech|sbc)\\.net$"
I do not get a match.
Any ideas why this is not working?
I am pasting my code below. I am using Fedora Core 1 with the gcc
that came with it.
Thanks,
Neil
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
/* The filter to match addresses */
regex_t PATTERN1;
regex_t PATTERN2;
/* Initialization */
void init() {
int status = regcomp(&PATTERN1,"\\.ameritech\\.net$",REG_ICASE);
if( status != 0 ) {
fprintf(stderr, "Could not compile regex pattern1\n");
exit(-1);
}
status = regcomp(&PATTERN2,"\\.(ameritech|sbc)\\.net$",REG_ICASE);
if( status != 0 ) {
fprintf(stderr, "Could not compile regex pattern2\n");
exit(-1);
}
}
int main(argc, argv)
int argc;
char *argv[];
{
/* Initialize */
init();
char buffer[1024] = "adsl-68-72-170-142.dsl.chcgil.ameritech.net";
int status = regexec(&PATTERN1, buffer, (size_t) 0, NULL, 0);
if( status == REG_NOMATCH )
printf( "Did not match pattern 1\n" );
else
printf( "Matched pattern 1\n" );
status = regexec(&PATTERN2, buffer, (size_t) 0, NULL, 0);
if( status == REG_NOMATCH )
printf( "Did not match pattern 2\n" );
else
printf( "Matched pattern 2\n" );
}
[ Post a follow-up to this message ]
|