当只有一次出现时,我的代码有效:
def result = "Text 1,1"
def matches = (result =~ /^.+\s([0-9],[0-9])$/ ).with { m -> m.matches() ? result.replace(/${m[ 0 ][ 1 ]}/, 'X'+m[ 0 ][ 1 ]+'X') : result }
assert "Text X,X" == matches
如果我的字符串包含多次出现,我该怎么办?
def result = "aaaa Text 1,1 Text 2,2 ssss"
谢谢