JavaScript RegExp i Modifier

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
ignoreCase flag

What You’ll Learn

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

01

i flag

ignoreCase

02

A = a

Letters only

03

/pat/i

Syntax

04

gi

Global + i

05

test()

Any case

06

vs [Aa]

Simpler

Introduction

By default, regular expressions distinguish uppercase from lowercase. The letter A in a pattern matches only capital A, not a. The i modifier removes that restriction for letters throughout the pattern.

Case-insensitive matching is one of the most common regex needs in web apps—search fields, filtering lists, validating emails or keywords where users may type any combination of upper and lower case letters.

Understanding the i Modifier

Append i to a regex literal or pass "i" in constructor flags. The RegExp instance sets ignoreCase: true, and the engine folds letter case during matching.

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

/cat/i.test("CAT");            // true

Digits, whitespace, and punctuation are unaffected. Only letters (and Unicode letter-like characters) participate in case folding.

💡
Beginner Tip

When validating user-typed words, add i instead of listing every case variant: /submit/i beats /[Ss][Uu][Bb][Mm][Ii][Tt]/.

How to Use the i Modifier

Enable case-insensitive matching on literals, constructors, and combined flags:

JavaScript
/hello/i;                          // case-insensitive literal
new RegExp("hello", "i");          // constructor
/error/gi;                         // global + ignoreCase

re.ignoreCase;                     // true when i is set
text.replace(/yes/gi, "ok");       // replace all case variants

Pair i with g when you need every case-insensitive match in a string, not just the first one.

📝 Syntax

JavaScript
/pattern/i           // ignoreCase
/pattern/gi          // global + ignoreCase
/pattern/ig          // same (order free)
new RegExp("p", "i") // constructor
regex.ignoreCase      // true | false

Common patterns

  • /word/i — match word in any letter case.
  • /error/gi — find every error/ERROR/Error in text.
  • /^[a-z]+$/i — letters only, any case (still matches A–Z via i).
  • re.ignoreCase — check whether the flag is active.

⚡ Quick Reference

GoalPattern / API
Case-insensitive match/pattern/i
Check flagregex.ignoreCase
All case variants/pat/gi
Replace any casestr.replace(/pat/gi, "x")
Case-sensitive (default)/pattern/ (no i)
Constructor formnew RegExp("pat", "i")

📋 With i vs without i

Same pattern, different case sensitivity.

Case-sensitive
/hello/

Exact letter case

ignoreCase
/hello/i

Any letter case

Manual class
[Hh][Ee]...

Verbose alternative

Global + i
/pat/gi

All + any case

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples cover test(), ignoreCase, gi combo, replace, and comparison with character classes.

📚 Getting Started

Match text regardless of letter case.

Example 1 — Case-Insensitive test()

Compare /hello/i with the default case-sensitive pattern.

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

How It Works

With i, the engine treats H and h as equivalent for matching purposes. Without i, only the exact case in the pattern matches.

📈 Practical Patterns

Properties, combined flags, and replacement.

Example 2 — Read the ignoreCase Property

Inspect whether a RegExp was created with the i flag.

JavaScript
const withI = /cat/i;
const withoutI = /cat/;

console.log(withI.ignoreCase);     // true
console.log(withoutI.ignoreCase);  // false
console.log(withI.flags);          // "i"
Try It Yourself

How It Works

ignoreCase is read-only and set at creation time. See the ignoreCase property tutorial for more detail.

Example 3 — Global Case-Insensitive Match with /error/gi

Find every occurrence regardless of letter case.

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

console.log(text.match(/error/gi));
// ["Error", "ERROR"]

console.log(text.match(/error/gi).length); // 2
Try It Yourself

How It Works

g finds all matches; i ignores case. Together they scan the full string for every case variant of the word.

Example 4 — Replace All Case Variants

Normalize every yes/YES/Yes to the same replacement.

JavaScript
const text = "Yes YES yes";

console.log(text.replace(/yes/gi, "ok"));
// "ok ok ok"
Try It Yourself

How It Works

Both g (all matches) and i (any case) are needed here. Omitting either flag leaves some variants unchanged.

Example 5 — /javascript/i vs Manual Character Classes

The i flag simplifies patterns that would otherwise list each case.

JavaScript
const text = "JavaScript rocks";

console.log(/javascript/i.test(text));     // true
console.log(/[Jj]ava[Ss]cript/.test(text)); // true
console.log(/javascript/.test(text));      // false
Try It Yourself

How It Works

Manual [Jj] classes work for short patterns but become unwieldy for long words. The i flag applies case insensitivity to the entire pattern at once.

🚀 Common Use Cases

  • Search boxes — find items whether users type upper or lower case.
  • Validation — accept YES, yes, or Yes as equivalent answers.
  • Log filtering — match ERROR, error, or Error in log lines.
  • URL/path checks — treat /API and /api the same when appropriate.
  • Keyword detection — flag prohibited words regardless of capitalization.
  • Replace normalization — swap all case variants in one pass with /gi.

Important Considerations

  • Letters onlyi does not make 5 match S or symbols match differently.
  • Unicode nuance — some locale-specific case pairs (e.g. Turkish I/i) may behave unexpectedly; test international input.
  • When case matters — passwords and base64 tokens usually must stay case-sensitive; omit i.
  • Flags are fixed — you cannot toggle i after creating the RegExp; build a new one.
  • Combine with g — use gi when you need all case-insensitive matches, not just the first.

🧠 How the i Modifier Ignores Case

1

Read pattern char

The engine takes the next letter from the pattern.

Parse
2

Fold case

With i, compare using case-insensitive rules for letters.

Fold
3

Match input char

h in the pattern matches H, h, etc.

Compare
4

Continue pattern

All letters fold; digits and symbols match literally.

📝 Notes

  • i is the ignoreCase flag (also called case-insensitive).
  • Flag order is free: /pat/gi equals /pat/ig.
  • Previous modifier: g global flag.
  • Next modifier: m multiline flag.
  • See also: ignoreCase property.
  • For case-sensitive matching, omit i or use explicit character classes.

Browser & Runtime Support

The i ignoreCase modifier is part of core JavaScript regular expression syntax.

Baseline · ES3+

RegExp i flag

Supported in every browser and Node.js version. The i flag enables case-insensitive letter matching.

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 Excellent

Bottom line: Safe everywhere. Use i when letter case should not affect whether a pattern matches.

Conclusion

The i modifier makes regex letter matching case-insensitive. Add it when users may type any mix of uppercase and lowercase, and combine with g to find or replace every case variant in a string.

Prefer /word/i over long manual character classes, remember that digits and symbols are unaffected, and keep patterns case-sensitive when it matters (passwords, encoded data). Next, learn the m multiline modifier.

💡 Best Practices

✅ Do

  • Use i for user-facing search and validation
  • Combine gi for all case-insensitive matches
  • Check ignoreCase when debugging regex behavior
  • Omit i when exact case is required
  • Test with mixed-case sample input

❌ Don’t

  • Add i to password or hash validation by default
  • Assume i affects digits or punctuation
  • Write [Aa][Bb]... when /ab/i suffices
  • Forget g when replacing all case variants
  • Expect to toggle i on an existing RegExp object

Key Takeaways

Knowledge Unlocked

Five things to remember about the RegExp i modifier

Match letters without worrying about uppercase vs lowercase.

5
Core concepts
📈 02

A = a

Letters.

Behavior
🚫 03

gi

All + any case.

Combine
🔒 04

/pat/i

Search.

Use case
🔢 05

No i

Passwords.

Caution

❓ 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'). The ignoreCase property on the instance becomes true.
No. ignoreCase applies to letters (and Unicode letter categories per the engine). 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 insensitivity to the entire pattern automatically, including character classes and groups.
The ignoreCase flag is core JavaScript regex syntax since ES3. It works in every browser and Node.js version.
Did you know?

HTML search inputs often feel case-insensitive because the browser or your JavaScript adds an i flag behind the scenes. When you write your own filter with regex, you must add i explicitly—/query/ alone will not match Query.

Continue to m multiline modifier

Learn how the m flag changes how ^ and $ anchors behave across multiple lines.

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.

6 people found this page helpful