I have this pattern [-]{23}[ ]*Page[ ]*[0-9]*[-]{23}
to extract the page number from an string like ----------------------- Page 1-----------------------
it works fine using javascript regex implementation:
var s = "----------------------- Page 1-----------------------";
alert( s.match(/[-]{23}[ ]*Page[ ]*[0-9]*[-]{23}/) != null);
match()
function returns the matched string value or null
if pattern does not match with string. The above code show true
my C code:
#include <assert.h>
#include <sys/types.h>
#include <regex.h>
//...
regex_t reg;
regmatch_t match;
char * line = "----------------------- Page 1-----------------------";
regcomp(®,
"[-]{23}[ ]*Page[ ]*[0-9]*[-]{23}",
REG_ICASE /* Don't differentiate case */
);
int r = regexec(®,
line, /* line to match */
1, /* size of captures */
&match,
0);
if( r == 0) { printf("Match!"); } else { printf("NO match!"); }
the if-statement above print NO match!
I have no idea how to fix this. Thanks in advance.