regular expression match Thursday, Thurs, Thur,Thu

邮差的信 提交于 2019-12-24 18:41:26

问题


I want a regexp to match partial weekday names. For example, I want to match "Thursday", "thurs", "thur" or "Thu". I tried "thu(rsday)?", but that only matched "thu" and "thursday". The complete regular expression to match abbreviated weekdays would be excessively long. I tried this regex string:

Mon(day)?|Tue(sday)?|Wed(nesday)?|Thu(rsday)?|Fri(day)?|Sat(urday)?|Sun(day)?

The strings I have look like this:

3-Dec Mon 1:00pm Premiere USPHL Sk3-Red

4-Dec Tue 8:10pm U16 USPHL Sk3-Red

6-Dec Thur 1:00pm Premiere USPHL Sk3-Red


回答1:


In Oracle I'd do this where I want to select where the string matches a weekday. I suspect you can tweak the regular expression to fit your environment:

with tbl(str) as (
  select '3-Dec Mon 1:00pm Premiere USPHL Sk3-Red' from dual union all
  select '4-Dec Tues 8:10pm U16 USPHL Sk3-Red' from dual union all
  select '6-Dec Thursday 1:00pm Premiere USPHL Sk3-Red' from dual
)
select str
from tbl
where regexp_like(str, ' (mon|tue(s)?|wed(nes)?|Thu(r)?(s)?|fri|sat(ur)?|sun)(day)? ', 'i');



回答2:


OK, thanks for the help. I ended up with this regexp:

(?i)((mon|tue(s)?|wed((((n)?e)?s)?)?|thu(r)?(s)?|fri|sat(ur)?|sun)(day)?)

A little more complicated than I wanted, but it works. I'll need plenty of comments in my code ;-)



来源:https://stackoverflow.com/questions/53640989/regular-expression-match-thursday-thurs-thur-thu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!