Ruby:“〜〜”是什么意思?(Ruby: What does the “!~” operator mean? [duplicate])
这个问题在这里已经有了答案:
!〜方法在Ruby 2中对 String做了什么 回答当声明语法如:
a !~ b其中a,b是变量,这是什么意思?
This question already has an answer here:
What does the !~ method do with String in Ruby 2 answersWhen declaring syntax such as:
a !~ bwhere a,b are variables, what does it mean?
最满意答案
这是正则表达式匹配的否定。
"a" !~ /b/ # => true当你想要检查一个字符串是否与特定模式不匹配时,这很有用。 例如,如果你想检查字符串s是否只包含数字,那么你可以这样做:
s !~ /\D/It is negation of =~, a regex match.
"a" !~ /b/ # => trueIt is useful when you want to check whether a string does not match a certain pattern. For example, if you want to check if string s includes only numbers, then you can do:
s !~ /\D/更多推荐
发布评论