Regex to match string containing two names in any order

后端 未结 8 2138
忘了有多久
忘了有多久 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:48

    You can do checks using lookarounds:

    ^(?=.*\bjack\b)(?=.*\bjames\b).*$
    

    Test it.

    This approach has the advantage that you can easily specify multiple conditions.

    ^(?=.*\bjack\b)(?=.*\bjames\b)(?=.*\bjason\b)(?=.*\bjules\b).*$
    

提交回复
热议问题