c regex not finding string -


i'm trying create collection of regexes in c, no success.

currently i'm trying find include statements following regex:

(#include <.+>)|(#include \".+\") 

here code:

#include <stdio.h> #include <stdlib.h> #include <regex.h>  char *regex_str = "(#include <.+>)|(#include \".+\")"; char *str = "#include <stdio.h>";  regex_t regex; int reti;  int main() {     /* compile regex */     reti = regcomp(&regex, regex_str, 0);      if (reti) {         printf("could not compile regex.\n");         exit(1);     }      /* exec regex */     reti = regexec(&regex, str, 0, null, 0);      if (!reti) {         printf("match\n");     } else if (reti == reg_nomatch) {         printf("no match\n");     } else {         regerror(reti, &regex, str, sizeof(str));         printf("regex match failed: %s\n", str);         exit(1);     }      /* free compiled regular expression if want use regex_t again */     regfree(&regex);      return 0; } 

the result is: no match

what doing wrong?

you might need escape match group:

char *regex_str = "\\(#include [\"<].*[\">]\\)"; 

which rolled 1 pattern.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -