I have a string: String s = "The input must be of format: '$var1$'-'$var1$'-'$var1$'".
I want to replace the text between the $ with another text, so the outcome may look on the console like:
"The input must be of format: '$REPLACED$'-'$REPLACED$'-'$REPLACED$'"
I came till s.replaceAll("\\$.+\\$", "\\$REPLACED\\$";, but that results in
"The input must be of format: '$REPLACED$'" (the first and the last $ are taken as borders).
How can I tell the regex engine, that there are several occurences and each need to be processed (=replaced)?
Thank for your help!
Edit:// Thanks for your help. The "greedy thing" was the matter. Adding a ? to the regex fixed my issue. The solution now looks like this (for those witha similar problem):
s.replaceAll("\\$.+?\\$", "\\$REPLACED\\$";