regex - how to get the array of strings that are inside curly braces in the source string in java -


"string" = string = "text">

This is {one} sample {string} in which {included} {substrings} {braces} inside the horoscope;

I want a string of string with its contents: {is}, {string}, {contains}, {substrings} {braces}

  "{is} a sample {string} in which {corporat} {substrings} are inside I curly (braces)"  

From it, it is taking all the characters that are in the middle of the first open curly braces and the last closing Kurli braces.

string string = "This is {a} flat {string} that contains {substrings} inside {brackets {braces}; // values ​​between curly braces Regular expression to get (a mistake, I think) string regex = "\\ {(. *) \\}"; Matcher matcher = Pattern.compile (regex) .Missher (source string); while (matcher. Find ()) {System.out.println (matcher.group (0))}} got a little bit of googling solution, which gave me ideas for the pattern

some time The libraries and functionality I spent with will need to provide this example ...

  string exp = "\\ {(. *?) \\}"; string value = "this { A} flat {string} that {keeps} {curly} {braces} inside {substrings}; Pattern Pattern = Pattern.compile (exp); Matcher matcher = pattern.matcher (value); List & lt; string & gt; ; Matches = new arreelist & lt; string & gt; (5); while (matcher.find ()) {string group = matcher.group (); matches.add (group);} string [] group = matches.to Array (new st Ing [max. Size ()]); Println (Arrays.toString (group));  

Which output

  [{}}, {string}, {included}, {substrings}, {braces}]  / Ex> 

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -