-1

To match the string behind the : :

TE: trailer

The expression will convert the string into trailer:

:1s/\v(.{-}):\s{1,}(.{-})/\2/

Why 1s/\v(.{-}):\s{1,}(.{-})/\2""/ convert the string into ""trailer instead of trailer""?

Almost the same result:1s/\v(.{-}):\s{1,}(.{-})/"\2"/ convert the string into ""trailer instead of "trailer"

1 Answer 1

1

Second capture group is non-gready and it captures nothing, so you essentially replace only TE: with \2 which is empty and "", and the result is ""trailer.

1s/\v(.{-}):\s{1,}(.*)/\2""/

or

1s/\v(.{-}):\s{1,}(.{-})$/\2""/

would make it trailer""

and

1s/\v(.{-}):\s{1,}(.{-})$/\2""/

to make it "trailer".

1
  • Indeed, I warned about the hazard of empty matches with non-greedy . in the OPs previous question.
    – D. Ben Knoble
    Mar 12 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.