Regex tester · Guide
Regex Match Case Insensitive: The i Flag and Its Limits
The `i` flag is the obvious answer and the right one most of the time. The exceptions — Unicode, locale-specific casing, and partial insensitivity — are worth knowing before they surprise you in production.
The flag
/hello/i // JavaScript
re.search(r'hello', s, re.I) # Python
Pattern.compile("hello", Pattern.CASE_INSENSITIVE) // Java
new Regex("hello", RegexOptions.IgnoreCase) // C#
(?i)hello # inline, works nearly everywhereThe inline (?i) form is useful when you can only supply a pattern string — a config file, a database column, an online tester that takes no flags.
ASCII by default
In Java and .NET, CASE_INSENSITIVE alone covers ASCII only. É will not match é until you add UNICODE_CASE (Java) — .NET handles Unicode by default but is culture-sensitive.
Python 3 is Unicode-aware by default; adding re.ASCII restricts it. JavaScript handles Unicode case folding correctly with the u flag.
The classic failure is Turkish: dotless ı and dotted İ do not fold to i and I the way English expects, so a case-insensitive match on a Turkish locale can behave differently than on an English one.
When not to use the flag
If only part of the pattern should be case-insensitive, a character class is more precise than making everything insensitive: [Cc]at\d+ rather than /cat\d+/i.
Some engines support scoped inline flags — (?i:cat)\d+ applies insensitivity to the group only, which is clearer than splitting the pattern.
Regex may be the wrong tool
For a simple containment check, lowercasing both sides and using a string function is faster and clearer than a regex. Reach for the flag when you are already matching a pattern.
For user-facing search, neither is enough on its own: you usually also want accent folding, so "cafe" finds "café". That is normalisation (NFD plus stripping combining marks), applied before matching.
Frequently asked questions
Does the i flag handle accented characters?
In Python and JavaScript with the u flag, yes. In Java you also need UNICODE_CASE.
How do I make only part of a pattern case-insensitive?
Use a character class such as [Cc]at, or a scoped inline group (?i:cat) where supported.
Is case-insensitive matching slower?
Slightly, since the engine folds case per character. It is rarely the bottleneck.
Ready to try it?
Open the free browser-based Regex tester and apply what you just read — no sign-up, runs locally.
Open the Regex tester tool