I want to replace all "%" with "%%" in my string. However, my string might also have "%{abc}" and this shouldn’t be replaced.
Input: My name is %{name} and my % score is %{percentage} %!
Output: My name is %{name} and my %% score is %{percentage} %%!
You can use this regex to match all
%not succeeded by{EDIT
To prevent replacement of
%%(to%%%%):Note that this will prevent replacement of
%%%, just in case some other behaviour is expected.Credit goes to @MichaelKohl for gsub. @ZainZafar (OP) for the complete solution.