Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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" ?
Pattern
Matcher
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 */
Add a comment
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
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
Pattern+Matcherwill help.