0

string sample: "universal studios japan"

How do i make so that it matches with "japan universal studios" AND also with "japan univer"

Right now I'm using the following to regex :

^(?=.*\bjapan\b)(?=.*\buniversal\b)(?=.*\bstudios\b)

which works but

^(?=.*\bjapan\b)(?=.*\buniver\b)

does not work. It has to be a complete match for the second word..

^(?=.*\bjapan\b)(?=.*\buniversal\b) would work..

What changes do i need to make?

revo
  • 47,783
  • 14
  • 74
  • 117
user1955934
  • 3,185
  • 5
  • 42
  • 68

1 Answers1

0
^(?=.*\bjapan\b)(?=.*\buniver(?:sal)?\b)

You can make sal optional.

See demo.

https://regex101.com/r/wDUC7j/1

vks
  • 67,027
  • 10
  • 91
  • 124