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

ilPittiz
  • 734
  • 1
  • 10
  • 23

1 Answers1

2

try

    s = s.replaceAll("\\$\\{(.+?)}", "$1");
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • [Dasblinkenlight](http://stackoverflow.com/users/335858/dasblinkenlight)'s solution is perfectly valid as well, so thank you both! – ilPittiz Apr 17 '13 at 14:11