I want to use regular expressions in pure C (not C++), but i cannot use it! I search the source in internet:
#include <stdio.h>
#include <regex.h>
int main(int argc,char *argv[])
{
regex_t regex;
int reti;
char msgbuf[100];
/* Compile regular expression */
reti = regcomp(®ex, "^a[[:alnum:]]", 0);
if (reti) {
fprintf(stderr, "Could not compile regex\n");
return 1;
}
/* Execute regular expression */
reti = regexec(®ex, "abc", 0, NULL, 0);
if (!reti) {
puts("Match");
}
else if (reti == REG_NOMATCH) {
puts("No match");
}
else {
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
return 1;
}
/* Free memory allocated to the pattern buffer by regcomp() */
regfree(®ex);
return 0;
}
But i have errors:
..path..b.c(9): error #2048: Undeclared identifier 'regex_t' (did you mean: ?).
..path..b.c(9): error #2001: Syntax error: expected ';' but found 'regex'.
..path..b.c(9): error #2048: Undeclared identifier 'regex' (did you mean: ?).
..path..b.c(14): warning #2018: Undeclared function 'regcomp' (did you mean: rename?); assuming 'extern' returning 'int'.
..path..b.c(21): warning #2018: Undeclared function 'regexec' (did you mean: rename?); assuming 'extern' returning 'int'.
..path..b.c(25): error #2048: Undeclared identifier 'REG_NOMATCH' (did you mean: ?).
..path..b.c(29): warning #2018: Undeclared function 'regerror' (did you mean: ?); assuming 'extern' returning 'int'.
..path..b.c(35): warning #2018: Undeclared function 'regfree' (did you mean: rename?); assuming 'extern' returning 'int'.
*** Error code: 1 ***
Why this happens? Or say me, where i can get PCRE header and lib file, maybe it will be easier with this lib.
Sorry for bad English, i am not eng.speaking