-2

I want to create regex where the {{if gender == }} will be fixed and "Male", "Female", "Both" and "Unknown" will be dynamic values to be checked. I have tried something like this

/^\{\{if gender == "Male"|"Female"|"Both"|"Unknown"\}\}$/i

but this only checks {{if gender == "Male" and it's not good. Also, I have tried something like this

/^\{\{if gender == ("Male"|"Female"|"Both"|"Unknown")\}\}$

but this only shows me a group. What am I doing wrong?

Milos
  • 569
  • 3
  • 8
  • 21

1 Answers1

1

You need to put parenthesis on the first part too and it works:

^(?:\{\{if gender ==) (?:"Male"|"Female"|"Both"|"Unknown")\}\}$

I am using ?: to make it Non-capturing group. Alternately, it can be used as follows:

^(\{\{if gender ==) ("Male"|"Female"|"Both"|"Unknown")\}\}$

Regex working link

adumred
  • 144
  • 5