Last active
March 17, 2018 19:12
-
-
Save ivanarrizabalaga/8596583 to your computer and use it in GitHub Desktop.
Groovy regexp capturing content inside curly brackets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher | |
import java.util.regex.Pattern | |
//Tring to capture whats inside the curly brackets | |
String input="xxx{var23.ID}yyy{something here.some more}--{}" | |
//The group is everything but a '}' | |
def pattern = ~/\{([^\}]*)\}/ | |
def result=pattern.matcher(input) | |
result.each{it-> | |
println it | |
} | |
//Output: | |
//[{var23.ID}, var23.ID] | |
//[{something here.some more}, something here.some more] | |
//[{}, ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment