该文档提到了三个正则表达式特定的运算符:
~ 回来了 Pattern=~ 撤退 Matcher==~ 回来了 boolean现在,我怎么能否定最后一个呢?(我同意其他人不能有任何有意义的否定.)
我尝试了一个明显的想法:
println 'ab' ==~ /^a.*/ // true: yay, matches, let's change the input
println 'bb' ==~ /^a.*/ // false: of course it doesn't match, let's negate the operator
println 'bb' !=~ /^a.*/ // true: yay, doesn't match, let change the input again
println 'ab' !=~ /^a.*/ // true: ... ???
Run Code Online (Sandbox Code Playgroud)
我想最后两个应该像这样解释:
println 'abc' != ~/^b.*/
Run Code Online (Sandbox Code Playgroud)
在哪里,我可以看到new String("abc") != new Pattern("^b.*")存在true.