fork(1) download
  1. #include <stdio.h>
  2. #include <regex.h>
  3.  
  4. int
  5. regex_match (char *pattern, const char *string)
  6. {
  7. int status;
  8. regex_t re;
  9. status = regcomp (&re, pattern, REG_EXTENDED|REG_NOSUB);
  10. if (status != 0)
  11. {
  12. return (0);
  13. }
  14. status = regexec (&re, string, (size_t) 0, NULL, 0);
  15. if (status != 0)
  16. {
  17. regfree (&re);
  18. return (0);
  19. }
  20. regfree (&re);
  21. return (1);
  22. }
  23.  
  24. int
  25. main (void)
  26. {
  27. char *string = "Ciao amore mio";
  28. char *re = "iao";
  29.  
  30. if (regex_match (re, string))
  31. {
  32. printf ("Il modello \"%s\" trova corrispondenza ",
  33. re);
  34. printf ("nella stringa \"%s\"\n", string);
  35. }
  36. else
  37. {
  38. printf ("Il modello \"%s\" ", re);
  39. printf ("NON trova corrispondenza ");
  40. printf ("nella stringa \"%s\"\n", string);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
Il modello "iao" trova corrispondenza nella stringa "Ciao amore mio"