I am using std::regex
and need to do a search and replace.
The string I have is:
begin foo even spaces and maybe new line(
some text only replace foo foo bar foo, keep the rest
)
some more text not replace foo here
Only the stuff between begin .... (
and )
should be touched.
I manage to replace the first foo by using this search and replace:
(begin[\s\S]*?\([\s\S]*?)foo([\s\S]*?\)[\s\S]*)
$1abc$2
However, how do I replace all three foo in one pass? I tried lookarounds, but failed because of the quantifiers.
The end result should look like this:
begin foo even spaces and maybe new line(
some text only replace abc abc bar abc, keep the rest
)
some more text not replace foo here
Question update:
I am looking for a pure regex solution. That is, the question should be solved by only changing the search
and replace
strings in the online C++ demo.