我剪掉了以下Java代码:
def offer = new OfferBuilder().id(1)
.rulesId(1)
.secondaryRulesId(0L)
.code("test code")
.characteristics([characteristics])
.build()
我想用以下Groovy替换它:
def offer = new Offer(id: 1, rulesId: 1, secondaryRulesId: 0L, code: "test code", characteristics: [characteristics])
我正在使用Intellij内置正则表达式替换:
new (\w+)Builder\((\)\s?\.(\w+)\(([a-zA-Z0-9\" \[\]]+))+\).build\(\)
替换字符串:
new $1($3: $4)
问题是我只能替换最后出现的匹配组,因此输出:
def offer = new Offer(characteristics: [characteristics])
我一直试图在重复的gruoup上使用捕获,但仍然无法使其工作。你能告诉我什么不见了吗?
答案 0 :(得分:0)
下面; 正则表达式定义;
regex : new\s+OfferBuilder\(\)(\.[^\s]*\([^\s]*\))*
检测你的:
new OfferBuilder().id(1)
.rulesId(1)
.secondaryRulesId(0L)
.code("test code")
.characteristics([characteristics])
.build()
用于对象参数:
(\.[^\s]*\([^\s]*\))*
然后你解析每个匹配的参数。