user8755872
user8755872

Reputation: 1

look for two string in Groovy

How am I able to regex for two different words in a string in Groovy? Curently I can only get it to work when looking for one string.

def r = "This is a line that only contains LookForMe and nothing else"
def result = r =~ ('LookForMe' || 'AndMeToo')
assert result instanceof Matcher
if (result) ...

I want to be able to look for the words 'LookForMe' or 'AndMeToo' and perform an action if either scenario is 'true'.

Upvotes: 0

Views: 338

Answers (1)

Dmitry
Dmitry

Reputation: 85

def r = "This is a line that only contains LookForMe and nothing else"
def result = (r =~ /.*LookForMe.*|.*AndMeToo.*/)
if(result) ...

Upvotes: 1

Related Questions