Guest User

Untitled

a guest
Nov 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /* match: search for regexp anywhere in text */
  2. int match(char *regexp, char *text)
  3. {
  4. if (regexp[0] == '^')
  5. return matchhere(regexp+1, text);
  6. do { /* must look even if string is empty */
  7. if (matchhere(regexp, text))
  8. return 1;
  9. } while (*text++ != '\0');
  10. return 0;
  11. }
  12. /* matchhere: search for regexp at beginning of text */
  13. int matchhere(char *regexp, char *text)
  14. {
  15. if (regexp[0] == '\0')
  16. return 1;
  17. if (regexp[1] == '*')
  18. return matchstar(regexp[0], regexp+2, text);
  19.  
  20. if (regexp[0] == '$' && regexp[1] == '\0')
  21. return *text == '\0';
  22. if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text))
  23. return matchhere(regexp+1, text+1);
  24. return 0;
  25. }
  26. /* matchstar: search for c*regexp at beginning of text */
  27. int matchstar(int c, char *regexp, char *text)
  28. {
  29. do { /* a * matches zero or more instances */
  30. if (matchhere(regexp, text))
  31. return 1;
  32. } while (*text != '\0' && (*text++ == c || c == '.')));
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment