For example :
String str = "bla bla ${foo} ${foo1}";
How to get words "foo" and "foo1" ?
maybe my string is :
String str1 = "${foo2} bla bla ${foo3} bla bla";
How to get words "foo2" and "foo3" ?
For example :
String str = "bla bla ${foo} ${foo1}";
How to get words "foo" and "foo1" ?
maybe my string is :
String str1 = "${foo2} bla bla ${foo3} bla bla";
How to get words "foo2" and "foo3" ?
You can use the regex Pattern
and Matcher
classes. For example:
String str = "bla bla ${foo} ${foo1}";
Pattern p = Pattern.compile("\\$\\{([\\w]+)\\}");
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group(1));
}
/* Result:
foo
foo1
*/
Pattern p = Pattern.compile("\\${(.*?)\\}");
Matcher m = p.matcher(input);
while(m.find())
{
//m.group(1) is your string. do what you want
}
this should work