Regex to match string containing two names in any order

后端 未结 8 2112
忘了有多久
忘了有多久 2020-11-22 05:15

I need logical AND in regex.

something like

jack AND james

agree with following strings

  • \'hi jack here is

8条回答
  •  离开以前
    2020-11-22 05:45

    Vim has a branch operator \& that is useful when searching for a line containing a set of words, in any order. Moreover, extending the set of required words is trivial.

    For example,

    /.*jack\&.*james

    will match a line containing jack and james, in any order.

    See this answer for more information on usage. I am not aware of any other regex flavor that implements branching; the operator is not even documented on the Regular Expression wikipedia entry.

提交回复
热议问题