I am a regex supernoob (just reading my first articles about them), and at the same time working towards stronger use of vim. I would like to use a regex to search for all inst
An interesting feature of Vim regex is the presence of \zs
and \ze
. Other engines might have them too, but they're not very common.
The purpose of \zs
is to mark the start of the match, and \ze
the end of it. For example:
ab\zsc
matches c
, only if before you have ab
. Similarly:
a\zebc
matches a
only if you have bc
after it. You can mix both:
a\zsb\zec
matches b
only if in between a
and c
. You can also create zero-width matches, which are ideal for what you're trying to do:
:%s/:\zs\ze\S/ /
Your search has no size, only a position. And them you substitute that position by " ". By the way, \S
means any character but white space ones.
:\zs\ze\S
matches the position between a colon and something not a space.