Regex to match string containing two names in any order

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

    Its short and sweet

    (?=.*jack)(?=.*james)
    

    Test Cases:

    [
      "xxx james xxx jack xxx",
      "jack xxx james ",
      "jack xxx jam ",
      "  jam and jack",
      "jack",
      "james",
    ]
    .forEach(s => console.log(/(?=.*james)(?=.*jack)/.test(s)) )

提交回复
热议问题