When there are only one occurrence my code works:
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
How can I do if my String contains several occurrences?
def result = "aaaa Text 1,1 Text 2,2 ssss"
Thanks
You could replace the above with:
Or, you could do: