I have been wondering, how to use case insensitive regular expression for a response validation in a form where there are different possible answers?

I have tried:
and it really works, but I want it to be case insensitive.

Is there an easiest way to make it Case Insensitive?

I did:

  1. [?i(name1|name2|name3)] – it didn't work, and it accepts names that are not in the parenthesis.
  2. [?i](name1|name2|name3) – same as what happened to number 1

Any help would be very much appreciated!

2 Answers 2


Use a non-capturing group to set flags, like this:


See RE2.


Try using this


It worked on mine.

  • Thanks @Kin ^_^
    – JDD
    Sep 13, 2022 at 4:05
  • That regex will match iname1, ?name1, name2, name3 and also an empty text string, but it will not match name1, Name1, Name2 or nAME3 as specified in the question. Square brackets [] signify a character class rather than a group. Jun 23 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.