Ignore Case

Regular expressions are case sensitive by default, but sometimes you don’t care whether text is upper or lower case. You can keep your regular expressions from being case sensitive using the ignore case flag (set with an i, so /ste(?:ph|v)en/gi finds every instance of 'Steven', 'steven', 'Stephen', and 'stephen' in a string). Note how the global flag and the ignore case flag can be (but don’t have to be) used together.

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.