Reputation: 1
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
Reputation: 85
def r = "This is a line that only contains LookForMe and nothing else"
def result = (r =~ /.*LookForMe.*|.*AndMeToo.*/)
if(result) ...
Upvotes: 1