Search code examples
javaregexregular-language

Java regular expression with groups


I would like to replace all occurences of strings like:

"{something1}
"{someother2}
"{thing3}

but how to deal with group that contains string, not chars?

-- edit:

e.g. given String:

sometext "{something1}hello

I would like to have

sometext hello

or better, but its only replaceAll parameter

sometext "hello

Solution

  • I guess you can use replaceAll:

    String b = a.replaceAll("\\{.*?\\}", "sometext ");

    This will replace all characters surrounded by curly braces with the replacement string.