正则表达式匹配月份名称后跟年份 [英] Regex to match month name followed by year
本文介绍了正则表达式匹配月份名称后跟年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,是否可以使用正则表达式来匹配February 2009"?
解决方案
沿着线
<前>\b(?:Jan(?:uary)?|Feb(?:ruary)?|...|Dec(?:ember)?) (?:19[7-9]\d|2\d{3})(?=\D|$)那个
<前>\b # 一个词边界(?: # 非捕获组一月)?# 一月)|二月(?:ruary)?#|...# 等等|十二月(?:灰烬)?# 十二月(灰烬)) # 结束组# 空间(?: # 非捕获组19[7-9]\d|2\d{3} # 1970-2999) # 结束组(?=\D|$) # 后跟:除数字或字符串结尾外的任何内容Is it possible to use a regex to match "February 2009", for example?
解决方案
Along the lines of
\b(?:Jan(?:uary)?|Feb(?:ruary)?|...|Dec(?:ember)?) (?:19[7-9]\d|2\d{3})(?=\D|$)
that's
\b # a word boundary (?: # non-capturing group Jan(?:uary)? # Jan(uary) |Feb(?:ruary)? # |... # and so on |Dec(?:ember)? # Dec(ember) ) # end group # a space (?: # non-capturing group 19[7-9]\d|2\d{3} # 1970-2999 ) # end group (?=\D|$) # followed by: anything but a digit or the end of string
这篇关于正则表达式匹配月份名称后跟年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文