/i (Case-Insensitive)
What is /i (Case-Insensitive)?
/i (Case-Insensitive): Match letters regardless of upper/lower case. The i flag makes a pattern ignore upper and lower case. /hello/i matches Hello, HELLO and hello. It is available in nearly every regex engine, written as /i in JavaScript and PHP or re.IGNORECASE in Python. Use it for input that people type, such as search boxes, commands or email domains. Users do not think about case, and your matching should not force them to.
Frequently asked questions about /i (Case-Insensitive)
What should you keep in mind with /i (Case-Insensitive)?
It is not a complete answer for comparing text, though. Some languages have case rules that a regex flag handles poorly, such as the German ß or the Turkish dotted i. For comparing whole values, such as checking whether an email address already exists, normalize both values with a proper lowercase function or use a case-insensitive database collation. Keep the flag for searching inside text.
At a glance
| Category | Regex flags |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |