How to implement this substring replacement rule?
- %% is replaced with % and %x is replaced with #
which would do, for example,
abc %x def => abc # def
abc %%x def => abc %x def
abc %%%x def => abc %# def
abc %%%%x def => abc %%x def
abc %%%%%x def => abc %%# def