string textvalue = "hello{myvar} discover {myvar2} {myvar3}"; string[] splitstring = textvalue.split("\\{*\\}");
what i'm getting output [{myvar, {myvar2, {myvar3]
in splitstring
but requirement preserve delimiters {}
i.e. [{myvar}, {myvar2}, {myvar3}]
.
required way match above output.
use so:
pattern p = pattern.compile("(\\{\\w+\\})"); string str = ... matcher m = p.matcher(str); while(m.find()) system.out.println(m.group(1));
note, code above untested words within curly brackets , place them in group. go on string , output string matches expression above.
an example of regular expression available here.
Comments
Post a Comment