Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # matches "3 miles", "5k", etc
- distance_regex = /
- (?: \s|\A ) # beginning of string of after whitespace
- ( \d+ (?:\.\d+)? ) # match integer or float
- \s? # optional whitespace
- ( m\.? # unit possibilities
- |
- m\.?i\.?
- |
- miles
- |
- k\.?
- |
- k\.?m\.?
- |
- kilometers )
- (?: \s|\Z|\.|, ) # legit pattern endings
- /ix
- ##
- # matches "22", "33:04", "1:04:03", etc
- # note: could be considered an over eager pattern. it also matches: "90:04" (90 minutes, 4 seconds)
- colon_time_regex = /
- (?: \s|\A ) # needs to be at the beginning of the string or after whitespace
- (?: (\d?\d): )? # hours part
- (?: (\d?\d): )? # minutes
- ( (\d?\d) # match seconds but ...
- (?! # be careful not to match other parts of the sentence ...
- \s? # optional whitespace
- ( m\.? # like distances ... eg 3 miles
- |
- m\.?i\.?
- |
- miles
- |
- k\.?
- |
- k\.?m\.?
- |
- kilometers )
- )
- )
- (?: \s|\Z|\.|, ) # legit pattern endings
- /ix
Add Comment
Please, Sign In to add comment