Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void regex(void)
- {
- 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;
- }
- /* 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;
- }
- /* Free memory allocated to the pattern buffer by regcomp() */
- regfree(®ex);
- }
Add Comment
Please, Sign In to add comment