Closed marcelocantos closed 4 years ago
It doesn't work to replace " "
with ""
then replace "\_"
with " "
. Unfortunately, it breaks for a\\_b
, which should match a\_b
, but will instead match a b
.
It almost works to only consider \_
after an odd-length chain of backslashes: s/((?:\A|[^\\])(?:\\\\)*)\\_/\1 /
. This has the problem that \_\_
won't match the second \_
because [^\\]
needs to match on the first _
, which has already been consumed. This could be solved in one pass if re2 supported look-behind assertions, (?<=...)
. Without it, two passes of the preceding substitution should suffice because the first pass eliminates all adjacencies.
/{"(?:\\x[[:xdigit:]]{2}|\\[nrt"\\]|[^\\])"}
/{ " (?: \\x[[:xdigit:]]{2} | \\[nrt"\\] | [^\\] ) " }
For literal spaces,
ab c
could be expressed asab\_c
.