There is a string object in java with its contents:
String sourceString="This {is} a sample {string} that {contains} {substrings} inside curly {braces}";
I want an array of string with its contents: {is},{string},{contains},{substrings}{braces}
Below is the code that I wrote to get the result, but the output that I get:
"{is} a sample {string} that {contains} {substrings} inside curly {braces}"
So basically it takes all the characters between the first open curly braces and the last closing curly braces.
String sourceString="This {is} a samle {string} that {contains} {substrings} inside curly {braces}";
String regex="\\{(.*)\\}";
Matcher matcher = Pattern.compile(regex).matcher(sourceString);
while (matcher.find()) {
System.out.println(matcher.group(0));
}
source
share