Remove "$ {anything}" from a string in java

I want to remove $ {anything} or $ {somethingelse} from the string, but I cannot 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 am sure that the solution is stupid, but there is no way to find it.

+4
source share
3 answers

Try the following:

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

.*? matches the shortest string followed by } .

+7
source

you delete any number { because you have {* instead .*

must be \\$\\{.*\\}

what really allows something between braces, do you want it to be only alpha or something like that?

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

+1
source

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

0
source

All Articles