I’m wondering how can I replace a character with another in a big string, only if the match is between { }
This:
bla bla % bla {ok text %nothing} some {% more} % text {yes %no ok} ok
To this:
bla bla % bla {ok text ^^nothing} some {% more} % text {yes ^^no ok}
ok
Notice the {% more} wasn’t changed because there was a space between the character and the letter.
Your is much appreciated.
If
{}are not nested and no}can occur outside of them, you can do things like:When the string is:
you would get:
If nested
{}are allowed, you could use:Which works as the first one, with the
[^{]*being replaced by([^{}]*+(?:{(?1)}[^{}]*+)*+), which is recursively checking for arbitrary nested{}.Example:
Output: