如何在Groovy中对字符串中的两个不同单词进行正则表达式?目前,我只能在寻找一个字符串时使它工作。

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


我希望能够查找单词“ LookForMe”或“ AndMeToo”,并在任何一种情况为“ true”时执行操作。

最佳答案

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

10-08 14:30