What is the \& pattern in Vim's Regex

后端 未结 2 706
一个人的身影
一个人的身影 2020-12-30 05:19

I recently came across the branch specifier in Vim regex builtins. Vim\'s help section on \\& contains this:

A branch is one or more concats         


        
2条回答
  •  礼貌的吻别
    2020-12-30 06:07

    \& can be used to match a line containing two (or more) words in any order. For example,

    /.*one\&.*two\&.*three

    will find lines containing one, two and three in any order. The .* is necessary because each branch must start matching in the same place.

    Note, the last branch is the one that participates in any substitution. For example, applying the following substitution:

    s/.*one\&.*two\&.*three/<&>/

    on the line

    The numbers three, two, and one

    results in

    , two, and one

提交回复
热议问题