Given the string:
This is_ an_example.
I want to produce:
This - is - an example.
IOW, replace all instances of ‘\s*_\s*’ with ’ - ’ (note the spaces on each side of the dash). Can this be done via rreplace? (Preferably in one call.) As far as I can tell, the standard regex ‘g’ operator for replacing all matches (e.g. ‘s/abc/def/g’) doesn’t work.
Ultimately I want to replace all of a set of certain characters in album and track names with ’ - ', but that just means using a group like ‘[\/;_]’ in place of merely ‘_’.
(To keep the strings simple here, I didn’t escape with ‘\’. Naturally I’ll do that in the real script.)