Advertisement
michciu

Untitled

Dec 4th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. regex
  2. /******************************************************************************
  3.  
  4.                             Online C Compiler.
  5.                 Code, Compile, Run and Debug C program online.
  6. Write your code in this editor and press "Run" button to compile and execute it.
  7.  
  8. *******************************************************************************/
  9.  
  10. #include <stdio.h>
  11.     #include <regex.h>        
  12. regex_t regex;
  13. int reti;
  14. char msgbuf[100];
  15.  
  16. int main()
  17. {
  18. /* Compile regular expression */
  19.     reti = regcomp(&regex, "^duuii", 0);
  20.     if (reti) {
  21.         fprintf(stderr, "Could not compile regex\n");
  22.         exit(1);
  23.     }
  24.  
  25. /* Execute regular expression */
  26.     reti = regexec(&regex, "dupa8", 0, NULL, 0);
  27.     if (!reti) {
  28.         puts("Match");
  29.     }
  30.     else if (reti == REG_NOMATCH) {
  31.         puts("No match");
  32.     }
  33.     else {
  34.         regerror(reti, &regex, msgbuf, sizeof(msgbuf));
  35.         fprintf(stderr, "Regex match failed: %s\n", msgbuf);
  36.         exit(1);
  37.     }
  38.  
  39. /* Free memory allocated to the pattern buffer by regcomp() */
  40.     regfree(&regex);
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement