Replacing all occurrences in a String I have a string like this : 

val content = "some_text{macro1}another_text{macro2}text"


I want to replace the {macro1} and {macro2} with macro1 and macro2, i.e. just to remove the { and }.

I wrote some piece of code which works fine, but for me it seems very hard to read: 

val Pattern = """\{(.*)\}""".r

Pattern.findAllIn(content).matchData.foldLeft(content) ( (newContent: String, current: Regex.Match) =&gt; {
     newContent.replace(current.group(0), current.group(1))
   }
)


How I can improve this code? Please note: since it's in Scala, I prefer it in the functional way.
Your desire to use the "functional way" is not well-motivated. Why do it "the functional way" when the "other way" is not only easier to read, but also common practice, and well-understood?

val stripCurly = "[{}]".r

val replaced = stripCurly.replaceAllIn(a, "")


If you want to have forced-matching of the braces consider:

val pure = """\{([^}]*)\}""".r
val pured = pure.replaceAllIn(content, "$1")


Note the use of the "not a } inside the {}" logic in the regex.

The examples above are running here in ideone