How do I get a Boolean value for a partial match using Groovy's regex?

Viewed 2212

Groovy has a regular expression "match operator" (==~). The documentation says it returns a Boolean, but requires a "strict match". It does not define "strict match".

I'm not familiar with any regex system where this expression is false. But, that's what Groovy is telling me.

'foo-bar-baz' ==~ /bar/ // => false

The find operator (=~) returns a Matcher, which can be indexed for matches and capture groups, apparently. But, I'd have to write an explicit test to have this expression return a Boolean.

('foo-bar-baz' =~ /bar/)[0] != null // => true

Two questions...

  1. What is a "strict match"?
  2. How do I get a Boolean value without adding a ton of garbage to my expression?
1 Answers
Related