JavaScript RegExp i Flag

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

What Is the i Flag?

The i flag (ignoreCase) makes letter matching case-insensitive. With /hello/i, the pattern matches hello, Hello, and HELLO—ideal for user input and search where case should not matter.

Remember
/pattern/i           // ignore letter case
regex.ignoreCase     // true when i is set

/hello/i.test("HELLO")  → true
/hello/.test("HELLO")   → false

digits & symbols: unchanged by i
combine: /error/gi
UsePrefer
Case-insensitive check/word/i.test(text)
Every case varianttext.match(/word/gi)
Read the flagregex.ignoreCase

How to Use the i Flag

Add i, then test, match, or replace as usual.

  1. Create a case-insensitive regex: /pattern/i or new RegExp("pattern", "i").
  2. Call test, match, or replace — letters fold case automatically.
  3. Add g when you need every occurrence: /pattern/gi.
  4. Confirm with regex.ignoreCase when debugging.
PieceRequired?Role
i flagYesIgnore letter case while matching
g flagOptionalFind / replace every case variant
Pattern letters—Any casing in the pattern is fine with i

Pseudocode

Pseudocode
re = /pattern/i

for each letter in pattern and input:
    compare using case fold
    (A ≡ a, B ≡ b, …)

digits / symbols:
    compare exactly (i has no effect)

if all parts match → success

Cheat Sheet

Keep these ignoreCase facts handy.

TopicDetail
Syntax/pattern/i or new RegExp(p, "i")
Check flagregex.ignoreCase
With global/pattern/gi (order does not matter)
AffectsLetters (case fold)
Does not affectDigits, spaces, punctuation
vs manual classes/hi/i ≈ /[Hh][Ii]/ (ASCII)
StandardES3+ (universal)

Live Preview

Compare case-sensitive vs case-insensitive matching on sample text.

Browser demo of ignoreCase — same idea as the examples below.

Result
/hello/i.test("Hello")
→ true

/* i folds letter case */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — test() With and Without i

Match hello regardless of letter case.

JavaScript
console.log(/hello/i.test("Hello World"));  // true
console.log(/hello/i.test("HELLO"));        // true
console.log(/hello/.test("Hello World"));   // false

console.log(/hello/i.ignoreCase);           // true
console.log(/hello/.ignoreCase);            // false
Try It Yourself

How It Works

  1. Add i. /hello/i sets ignoreCase to true.
  2. Fold letters. "Hello" and "HELLO" both match the pattern.
  3. Without i. /hello/ requires exact lowercase — "Hello" fails.
  4. Check the property. ignoreCase mirrors the flag at creation time.

Example 2 — Find Every Case Variant with gi

Combine g and i to collect all case variants in a string.

JavaScript
const text = "Error: file not found. ERROR logged.";

console.log(text.match(/error/gi));  // ["Error", "ERROR"]
console.log(text.match(/error/g));   // null (exact "error" missing)
Try It Yourself

How It Works

  1. Two flags. g finds every match; i ignores case.
  2. Collect variants. "Error" and "ERROR" both match /error/gi.
  3. Global alone fails. /error/g looks for lowercase only → null.
  4. Order free. gi and ig are the same flags.

Example 3 — Case-Insensitive replace

Normalize every spelling of a word with replace and gi.

JavaScript
const text = "I love js and JS and Js";

console.log(text.replace(/js/gi, "JavaScript"));
// "I love JavaScript and JavaScript and JavaScript"

console.log(text.replace(/js/g, "JavaScript"));
// "I love JavaScript and JS and Js"  (only lowercase js)
Try It Yourself

How It Works

  1. gi replaces all casings. js, JS, and Js all become "JavaScript".
  2. g alone is exact. Without i, only lowercase js is replaced.
  3. New string returned. The original text is unchanged.
  4. Common cleanup. Useful for normalizing tags, brands, or keywords from user input.

Edge Cases & Pitfalls

Check these before relying on ignoreCase.

scope

Letters only

i does not change how digits or punctuation match. /a1/i still requires the digit 1.

unicode

Locale case rules differ

Some languages have special case mappings (e.g. Turkish I/ı). For complex Unicode, consider the u flag and explicit tests.

exact

Do not use i when case matters

Passwords, codes, and case-sensitive IDs should use a regex without i.

classes

Prefer /word/i over huge classes

Manual /[Ww][Oo]…/ works for ASCII but is harder to maintain than a single i flag.

Browser & Runtime Support

The i (ignoreCase) flag is part of core JavaScript regular expression syntax (ES3+).

✓ Baseline · ES3+

RegExp i / ignoreCase

Supported in every browser and Node.js version. Case-insensitive matching works everywhere.

99% Universal syntax
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
i flag Excellent

Bottom line: Safe everywhere. Use i for flexible letter matching; combine with g when you need every case variant.

Performance Notes

ApproachCostBest for
/word/i~same as case-sensitiveNormal case-insensitive checks
/[Ww][Oo]…/Similar, harder to writeAvoid for long words
toLowerCase() + matchExtra string copyFine for short inputs; i is simpler

Case folding is handled by the engine. Prefer /pattern/i over building large character classes or lowercasing the whole string first unless you have a specific reason.

Key Takeaways

  • Role: i makes letter matching case-insensitive.
  • Check: regex.ignoreCase mirrors the flag.
  • Combo: use gi to find / replace every case variant.
  • Scope: letters fold; digits and symbols stay exact.

One line: add i when letter case should not matter — and skip it when case is part of the meaning.

Frequently Asked Questions

The i flag (ignoreCase) makes letter matching case-insensitive. /hello/i matches hello, Hello, HELLO, and HeLLo because uppercase and lowercase letters are treated as equivalent.
Append i to the literal: /pattern/i, combine flags like /pattern/gi, or pass 'i' in new RegExp('pattern', 'i'). Then regex.ignoreCase is true.
No. ignoreCase applies to letters. Digits, spaces, and symbols match the same with or without i.
Yes. /error/gi finds every case variant of error in a string. Flag order does not matter: gi and ig are equivalent.
For ASCII letters they match the same strings, but /word/i is shorter and applies case folding to the whole pattern automatically.
The ignoreCase flag is core JavaScript regex syntax since ES3. It works in every browser and Node.js version.

Next: m modifier

Learn how the multiline flag changes ^ and $.

m modifier tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful