1

I'm trying to figure out how to replace with Java 1.6 in strings like

hello ${world }!   ${txt + '_t'}<br/> ${do_not_replace

any substring identified between '${' and '}' with the same substring without these delimiters. So the output for the string above should be

hello world !   txt + '_t'<br/> ${do_not_replace

I identified a working pattern that allows me to replace the substrings with a fixed string

str.replaceAll('[${](.*?)}', '_')

and i know that i cannot use named groups with this version of Java.

Any suggestion for a simple solution to this problem are highly appreciated! Many thanks

1
  • "and i know that i cannot use named groups with this version of Java" Numbered groups are OK, though :) Commented Apr 17, 2013 at 10:40

1 Answer 1

2

try

    s = s.replaceAll("\\$\\{(.+?)}", "$1");
Sign up to request clarification or add additional context in comments.

1 Comment

Dasblinkenlight's solution is perfectly valid as well, so thank you both!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.