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
  • 45,845
  • 14
  • 70
  • 113
user1955934
  • 2,561
  • 4
  • 36
  • 58

1 Answers1

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

You can make sal optional.

See demo.

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

vks
  • 65,133
  • 10
  • 87
  • 119