The regular expression trick here is the (?=re) That’s called the
“zero-width positive lookahead”. It matches, but it does not consume
the string; so the gsub! will only replace the characters that are NOT
inside (?=re).
Man, that was right there, but I was blocking on it. (-;
I had to pull my pickaxe off the shelf and look it up, too. Page 327
in the second edition if you’re interested in reading about it. It’s
in the first edition, too, that is available online.
Blessings,
TwP
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.