我有以下正则表达式来查找名为 EXTRACT 的单词,但我需要找到另一项名为 REPLICAT 的作品。所以,复制 |提炼。如何用一个表达式来做到这一点。
def matcher = rawTerminalText =~ /(?m)(EXTRACT +RUNNING +)(.*?\w)( +)(\d{2}):(\d{2}):(\d{2})( +)(.*?\w)( +)(.*?$)/
我尝试了以下方法,但不起作用。
def matcher = rawTerminalText =~ /(?m)((^| )(REPLICAT|EXTRACT)+$ +RUNNING +)(.*?\w)( +)(\d{2}):(\d{2}):(\d{2})( +)(.*?\w)( +)(.*?$)/
最佳答案
如果您只想知道字符串中是否存在给定的单词?然后使用下面的正则表达式?
def rawText=" The Word which i am looking for is, REPLICAT and EXTRACT"
def Word= /^.*\b(REPLICAT|EXTRACT)\b.*$/;
def findWord= (rawText =~ /$Word/);
log.info findWord.count;
Output:
count will return 1: found
count will return 0:not found
关于java groovy提取两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51760099/