开发者

Ruby Regex How to specify not to match

开发者 https://www.devze.com 2023-03-31 10:43 出处:网络
How do you say not to match in Ruby Regex ex. you do not want to return true if it sees \'error\' /\\b(error)\\开发者_如何学Gob/i

How do you say not to match in Ruby Regex

ex. you do not want to return true if it sees 'error'

/\b(error)\开发者_如何学Gob/i

I know this returns true when it sees error, how do you say 'not' in this case? thanks!


Use the proper Ruby operator:

/\b(error)\b/i !~ someText


I would do something like the following excuse the /error/ pattern not sure exactly what you want to match here

return true unless b =~ /error/

or

return true if b !~ /error/
0

精彩评论

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

关注公众号