def aString = '[Something-26607] Updating another.txt [Something2] Updating something.txt [Something2] Updating something.txt fsfsfs' Is there a way in groovy to get only unique parts between the square brackets and store them in a variable so after I can call them in a for loop. So I will iterate over them
Something-26607 Something2 I have tried:
def matcher = aString =~ (/\[(?<issue>[^]]+)]/) def result = matcher.find() ? matcher.group('issue') : "" print result but I get only get the first match:
Something-26607
while (matcher.find()) {and use a pattern likeString regex = "\\[(?<issue>[^]]+)](?!.*\\1)";to find the unique matches in the string, or use your original pattern and use a Set for example. The values are in group 1 of the pattern.