I am using below regex to abc1,cde2,efg3 replace with hello but somehow it's not working
:%s/\(\d\{2}:\d\{2}:\d\{2\}\s\)\([A-z0-9]*\)/hello/gc
Mar 17 02:25:01 abc1 micro: Starting use.slice.
Mar 17 02:25:01 cde2 micro: Starting use.slic
mar 17 02:25:01 efg3 micro: Starting use.slic
You can use this substitute command in vim
:
%s/\v(\d{2}:\d{2}:\d{2}\s+)[a-zA-Z0-9]+/\1hello/g
\v
is used for very magic that avoids escaping as per older BRE syntax.\1
is back-reference of captured group #1You can use \zs
to set where the match will start in the substitution.
:%s/\d\{2}:\d\{2}:\d\{2\}\s\zs[A-z0-9]*/hello/gc
For more help see :h /\zs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With