相关疑难解决方法(0)

如何否定Groovy匹配运算符?

文档提到了三个正则表达式特定的运算符:

  • ~ 回来了 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.

regex groovy

23
推荐指数
1
解决办法
1万
查看次数

标签 统计

groovy ×1

regex ×1