tags:

views:

100

answers:

3

I want to remove ${anything} or ${somethingelse} from a string, but i dont find the regex.

My actual code

String url = http://test.com/index.jsp?profil=all&value=${value}
String regex = "\\$\\{*\\}";
url = url .replaceAll(regex, ""); // expect http://test.com/index.jsp?profil=all&value= 
//but it is http://test.com/index.jsp?profil=all&value=${value}

i'm sure the solution is stupid, but no way to find.

+1  A: 

you're removing any number of {'s, because you have {* instead of .*

should be \\$\\{.*\\}

that will indeed allow anything between the braces, do you want that to be alpha only or something?

that would be \\$\\{[a-zA-Z]*\\}

John Gardner
+8  A: 

Try this one:

"\\$\\{.*?\\}"

The .*? matches the shortest possible string that is followed by }.

tangens
It works ! thx !
Antoine
@Antoine Meausoone Then mark the answer as accepted (tick below the vote counter)
Bozho
yeah i had to wait 15 minutes, and thx again you saved my week-end :)
Antoine
A: 

Another solution would be \\$\\{[^\\}]*\\} (any character different than })