I have a string like this : val content = some_text{macro1}another_text{macro2}textI 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 = \{(.*)\}.rPattern.findAllIn(content).matchData.foldLeft(content) ( (newContent: String, current: Regex.Match) => {     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.
Replacing all occurrences in a String
strings;regex;scala
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 = [{}].rval replaced = stripCurly.replaceAllIn(a, )If you want to have forced-matching of the braces consider:val pure = \{([^}]*)\}.rval 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