java groovy提取两个字符串

标签 java groovy

我有以下正则表达式来查找名为 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/

相关文章:

google-app-engine - Google-App-Engine 上的 Grails - 死了吗?

grails - 如何使groovy @Deprecated属性在Eclipse/IntelliJ中显示为不赞成使用(('strikethrough')?

java - 从 CXF 2.7 升级到 CXF 3.0

java - 如何使用相关的自动递增 ID 保存具有 OneToMany 关系的实体

java - IntelliJ 项目,其中每个模块都有自己的 git 存储库

java - 转换变量的问题

oop - Grails中的服务方法或域静态方法?

java - Spring 启动: hibernate cannot mapping entity to table in postgresql: spring boot

java - 如何使用泰坦 API?

java - 从字符串转换 map 对象 "[a:12,b:[a:b,c:d]]"