Background
I would like to extract a piece of information out of a string. For example,
NO PARKING (SANITATION BROOM SYMBOL) 8-9:30AM TUES & FRI
Because it's only TUES
and FRI
. It's not a range of days so I would like to just get ['TUES', 'FRI']
However, for something like
2 HOUR PARKING 9AM-5PM MON THRU SAT
It would be a range of days so the result would be ['MON', 'TUES', 'WED', 'THURS', 'FRI', 'SAT']
I have this regex which works with a range of days but I would like to modify to except just one rule.
\b((?:(?:MON|MONDAY|TUES|TUESDAY|WED|WEDNESDAY|THURS|THURSDAY|FRI|FRIDAY|SAT|SATURDAY|SUN|SUNDAY)\s*)+)(?=\s|$)
It works with
NO STANDING 11AM-7AM MON SAT
which extracts MON
and SAT
. But I don't want it to match
NO PARKING (SANITATION BROOM SYMBOL) 8-9:30AM TUES & FRI
Because I have another regex which I want it to be matched.
If you have many regex I would suggest running them in specific order (give them a priority) such that the more specific regex / more important ones will match first. That way you could stop matching if one regex matched, in your case the "other" regex.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.