I have similar text on more lines:
_AB_ _ABC_ _
OR _ _A_ _ABC_
I need to replace only the underscores that delimit some text. So I need:
=AB= =ABC= _
OR _ =A= =ABC=
How to match each pattern?
Try:
%s/_\([A-Za-z]\+\)_/=\1=/g
Where
[A-Za-z]
matches the chars A-Z and a-z. You could add other chars between []
. Note: If you want to add a dash (-
), it has to be the first char after the opening [
.\+
means "one or more".[A-Za-z]
with \a
(or you could use \w
to add [0-9]` too). See :h /character-classes
\w
, but that would also add the underscore. But \a
is good (and I didn't knew it :-)).
/[[:alnum:]]
. (Or do forget them...they're not particularly short and they're ASCII only. :)