开发者

I am validating for RegEx errors -- how can I return which keyword, it failed on?

I'm passing new objects through thi开发者_运维技巧s set of regex :

(?i)exp\s|(?i)expire\s|(?i)print|(?i)mention|(?i)spring|(?i)summer|(?i)winter|(?i)jan(\s|\.)|(?i)january|(?i)february|(?i)feb(\.|\s)|(?i)march|mar(\.|\s)|(?i)april|(?i)june|(?i)july|(?i)august|(?i)aug(\s|\.)|(?i)september|(?i)sept(\.|\s)|(?i)november|(?i)nov(\.|\s)|(?i)december|(?i)dec(\.|\s)|(?i)holiday|(?i)christmas|(?i)holloween|(?i)easter|(?i)season|(?i)ends|(?i)end

If it errors, for example on the word christmas , how can I dynamically pull the word it errors on, and display it as the cause of the error?


$~ will be set to a MatchData object. If you then call $~.captures, you should get an array of matches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜