Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. # matches "3 miles", "5k", etc
  2. distance_regex = /
  3. (?: \s|\A ) # beginning of string of after whitespace
  4. ( \d+ (?:\.\d+)? ) # match integer or float
  5. \s? # optional whitespace
  6. ( m\.? # unit possibilities
  7. |
  8. m\.?i\.?
  9. |
  10. miles
  11. |
  12. k\.?
  13. |
  14. k\.?m\.?
  15. |
  16. kilometers )
  17. (?: \s|\Z|\.|, ) # legit pattern endings
  18. /ix
  19.  
  20. ##
  21.  
  22. # matches "22", "33:04", "1:04:03", etc
  23. # note: could be considered an over eager pattern. it also matches: "90:04" (90 minutes, 4 seconds)
  24. colon_time_regex = /
  25. (?: \s|\A ) # needs to be at the beginning of the string or after whitespace
  26. (?: (\d?\d): )? # hours part
  27. (?: (\d?\d): )? # minutes
  28. ( (\d?\d) # match seconds but ...
  29. (?! # be careful not to match other parts of the sentence ...
  30. \s? # optional whitespace
  31. ( m\.? # like distances ... eg 3 miles
  32. |
  33. m\.?i\.?
  34. |
  35. miles
  36. |
  37. k\.?
  38. |
  39. k\.?m\.?
  40. |
  41. kilometers )
  42. )
  43. )
  44. (?: \s|\Z|\.|, ) # legit pattern endings
  45. /ix
Add Comment
Please, Sign In to add comment