Armand
Armand

Reputation: 24353

Why can't Groovy regex matchers be negated?

Can anyone explain the following?

println('x' ==~ /x/)
println('x' !=~ /x/)

result:

true
true

Upvotes: 2

Views: 712

Answers (1)

phlogratos
phlogratos

Reputation: 13924

There is no !=~ operator in groovy. It's a combination of != and ~.

println('x' !=~ /x/)

is equivalent to

println('x' != (~ /x/))

What you need is

println(!('x' ==~ /x/))

Upvotes: 4

Related Questions