Quote:
Originally Posted by astrogeek
Your regex tells it to remove space and only capture the last character, (.), hence \e. The trailing + matches multiple characters, but only captures and replaces the last one.
Try this, assuming that you want to leave surrounding space intact:
Code:
s/\([^ \t]\)/\\\1/g
...
\a\b\c\d\e
Or to remove leading whitespace:
Code:
s/^\s*\([^ \t]\)/\\\1/g
...
\a\b\c\d\e
|
I tried your second suggestion, but it gave me
Code:
s/^\s*\([^ \t]\)/\\\1/g
\abcde
which seemed reasonable, because '[...]' should just access one character, so I then did
Code:
s/^\s*\([^ \t]\)\+/\\\1/g
\e
the same as my original effort, and
Code:
s/^\s*\([^ \t]\+\)/\\\1/g
\abcde
But finally this did work
Code:
s/\S/\\&/g
\a\b\c\d\e
and I guess it translates as
\S the next non-whitespace character
\\& a backslash in front of current search result
/g do every one in the line
That gave me the clue that fixing it to the start of the line was the problem, because both of these work too.
Code:
s/\([^\t ]\)/\\\1/g
s/\s*\(.\)/\\\1/g
Many thanks for your help.