Regex: ignore case sensitivity

Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it:

/G[a-b].*/i

string.match("G[a-b].*", "i")

Check the documentation for your language/platform/tool to find how the matching modes are specified.

If you want only part of the regex to be case insensitive (as my original answer presumed), then you have two options:

  1. Use the (?i) and [optionally] (?-i) mode modifiers: (?i)G[a-b](?-i).*
  2. Put all the variations (i.e. lowercase and uppercase) in the regex – useful if mode modifiers are not supported: [gG][a-bA-B].*

One last note: if you’re dealing with Unicode characters besides ASCII, check whether or not your regex engine properly supports them.

Leave a Comment