re.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. *
  3. * Mini regex-module inspired by Rob Pike's regex code described in:
  4. *
  5. * http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
  6. *
  7. *
  8. *
  9. * Supports:
  10. * ---------
  11. * '.' Dot, matches any character
  12. * '^' Start anchor, matches beginning of string
  13. * '$' End anchor, matches end of string
  14. * '*' Asterisk, match zero or more (greedy)
  15. * '+' Plus, match one or more (greedy)
  16. * '?' Question, match zero or one (non-greedy)
  17. * '[abc]' Character class, match if one of {'a', 'b', 'c'}
  18. * '[^abc]' Inverted class, match if NOT one of {'a', 'b', 'c'} -- NOTE: feature is currently broken!
  19. * '[a-zA-Z]' Character ranges, the character set of the ranges { a-z | A-Z }
  20. * '\s' Whitespace, \t \f \r \n \v and spaces
  21. * '\S' Non-whitespace
  22. * '\w' Alphanumeric, [a-zA-Z0-9_]
  23. * '\W' Non-alphanumeric
  24. * '\d' Digits, [0-9]
  25. * '\D' Non-digits
  26. *
  27. *
  28. */
  29. #ifdef __cplusplus
  30. extern "C"{
  31. #endif
  32. /* Typedef'd pointer to get abstract datatype. */
  33. typedef struct regex_t* re_t;
  34. /* Compile regex string pattern to a regex_t-array. */
  35. re_t re_compile(const char* pattern);
  36. /* Find matches of the compiled pattern inside text. */
  37. int re_matchp(re_t pattern, const char* text);
  38. /* Find matches of the txt pattern inside text (will compile automatically first). */
  39. int re_match(const char* pattern, const char* text);
  40. #ifdef __cplusplus
  41. }
  42. #endif