I have a Java string that may contain "{
" and "}
" pairs, multiple times, inside a larger string:
"My name is {name}. I am a {animal}. I like to {activity} whenever it rains."
etc. I am trying to write code that would strip out all instances of these pairs:
"My name is . I am a . I like to whenever it rains."
These pairs can occur anywhere inside the string, and may not occur at all. Obviously a String#replaceAll(someRegex, "")
is in order here, but I can't seem to get the someRegex
right:
// My best attempt.
String stripped = toStrip.replaceAll("{*}", "");
Any ideas? Thanks in advance.