Ruby正则表达式方法!〜 [英] Ruby regular expression method !~
本文介绍了Ruby正则表达式方法!〜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不记得在哪里学习了String
类的!~
方法.但是我知道它会将字符串与正则表达式进行比较,并检查字符串是否与正则表达式不匹配.参见下面的示例.
I don't remember where I learned the !~
method of the String
class. However I know it compares a string to a regex and check whether the string not match the regex. See my below example.
C:\>irb
irb(main):001:0> "abba" =~ /(\w)(\w)\2\1/i
=> 0
irb(main):002:0> "xxxx" =~ /(\w)(\w)\2\1/i
=> 0
irb(main):003:0> "asdf" =~ /(\w)(\w)\2\1/i
=> nil
irb(main):004:0> "asdf" !~ /(\w)(\w)\2\1/i
=> true
irb(main):005:0> "asdf" !~ /asdf/i
=> false
irb(main):006:0>
我想找到该方法的更多信息,但在String
和Regexp
的rdoc中都找不到.任何人都可以提供帮助吗?
I want to find more information of the method but I can't find it in the rdoc of both String
and Regexp
. Anyone can give some help?
谢谢.
推荐答案
Since this is the method you can find it here in the Methods filter. I've found this description.
obj!〜其他→true或false
如果两个对象不匹配(使用=〜方法),则返回true,否则返回false.
Returns true if two objects do not match (using the =~ method), otherwise false.
这篇关于Ruby正则表达式方法!〜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文