JavaScript RegExp ignoreCase Property

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
i flag · A = a

What You’ll Learn

The ignoreCase property is true when a RegExp was built with the i flag. That tells JavaScript to treat uppercase and lowercase letters as equivalent—so /hello/i matches "Hello", "HELLO", and "hello".

01

Property

regex.ignoreCase

02

i flag

/pat/i

03

Boolean

true / false

04

Letters

A matches a

05

Combine

gi flags

06

Read-only

Fixed flags

Introduction

By default, regular expressions are case-sensitive. The pattern /javascript/ matches lowercase "javascript" but not "JavaScript" or "JAVASCRIPT".

The ignoreCase (i) flag removes that restriction for letters. The ignoreCase property reports whether that flag is active. You set it at creation with /pattern/i or new RegExp("pattern", "i"), then read regex.ignoreCase in your code.

Understanding the ignoreCase Property

RegExp.prototype.ignoreCase is a read-only boolean:

  • true — the i flag is set; letters match regardless of case.
  • false — default behavior; A and a are different characters.
  • Reflects flags — also visible in regex.flags when it contains "i".
  • Immutable — you cannot flip ignoreCase after construction; create a new RegExp instead.
  • Letters only — digits, spaces, and punctuation are unaffected by the i flag.
JavaScript
/hello/.test("Hello");   // false (case-sensitive)
/hello/i.test("Hello");  // true  (ignoreCase)

const regex = /error/i;
console.log(regex.ignoreCase); // true
💡
Beginner Tip

When validating user input like emails or usernames, case-insensitive matching is often what you want. Add i instead of duplicating every letter as [Aa].

How to Use ignoreCase in JavaScript

Set the flag at creation, then use normal RegExp methods. The engine handles case folding automatically:

JavaScript
const keyword = /warning/i;

keyword.test("WARNING");              // true
"Error and ERROR".match(/error/i);    // ["Error"]
"Yes YES yes".replace(/yes/gi, "ok"); // "ok ok ok"

Pair i with g when you need every case-variant match in a string, or with m for multiline text that also ignores case.

📝 Syntax

JavaScript
regex.ignoreCase

How to set ignoreCase mode (at creation)

JavaScript
/pattern/i
new RegExp("pattern", "i")
new RegExp("pattern", "gi")   // global + ignoreCase

Return value

  • true if the i flag is present.
  • false otherwise.

⚡ Quick Reference

GoalCode
Check ignoreCase flagregex.ignoreCase
Case-insensitive literal/hello/i
Find all case variantsstr.match(/word/gi)
Replace ignoring casestr.replace(/error/gi, "fixed")
Validate extension/\.(jpg|png)$/i
See all flagsregex.flags

📋 Case-Insensitive vs Case-Sensitive

The same pattern with and without the i flag.

ignoreCase: false
/hello/

Exact case

ignoreCase: true
/hello/i

Any case

Manual alt
[Hh][Ee]...

Verbose

gi combo
/pat/gi

All + any case

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples show how ignoreCase changes matching for real-world text.

📚 Getting Started

See ignoreCase true vs false on two regexes.

Example 1 — Read the ignoreCase Property

Compare a regex with and without the i flag.

JavaScript
const withIgnoreCase = /hello/i;
const withoutIgnoreCase = /hello/;

console.log(withIgnoreCase.ignoreCase);     // true
console.log(withoutIgnoreCase.ignoreCase);  // false
Try It Yourself

How It Works

The trailing i in the literal sets ignoreCase to true. Without it, letter case must match exactly.

📈 Practical Patterns

Testing, matching, replacing, and inspecting flags.

Example 2 — Case-Insensitive test()

Detect a keyword regardless of how the user typed it.

JavaScript
const sensitive = /javascript/;
const flexible = /javascript/i;

console.log(sensitive.test("JavaScript"));  // false
console.log(flexible.test("JavaScript"));   // true
console.log(flexible.test("JAVASCRIPT"));   // true
Try It Yourself

How It Works

With ignoreCase enabled, the engine treats J and j as the same letter at each position in the pattern.

Example 3 — Find All Case Variants with gi

Combine global and ignoreCase to collect every occurrence.

JavaScript
const text = "Error found: ERROR and error.";

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

How It Works

The g flag finds all matches; i ensures each match ignores letter case. Together they power search-and-highlight features.

Example 4 — Replace Text Ignoring Case

Normalize mixed-case words in one pass.

JavaScript
const log = "WARNING: Disk full. Warning again.";

const cleaned = log.replace(/warning/gi, "Notice");
console.log(cleaned);
// "Notice: Disk full. Notice again."
Try It Yourself

How It Works

replace with gi swaps every case variant. The replacement text uses the casing you provide in the second argument.

Example 5 — Compare ignoreCase with flags

Inspect flags when building regexes dynamically.

JavaScript
const regex = new RegExp("hello", "gi");

console.log(regex.ignoreCase);           // true
console.log(regex.global);               // true
console.log(regex.flags);                // "gi"
console.log(regex.flags.includes("i"));  // true
Try It Yourself

How It Works

ignoreCase is the boolean shortcut for the i slice of flags. Use it to branch logic or log which modes a dynamic regex uses.

🚀 Common Use Cases

  • Search boxes — find keywords whether users type JavaScript or javascript.
  • Form validation — accept .PNG, .png, and .Png file extensions.
  • Log parsing — detect ERROR, Error, and error in server output.
  • URL routing — match path segments without caring about case (when appropriate).
  • Content filters — block banned words in any casing.
  • Dynamic regex — pass "i" in the flags string from user settings.

Important Considerations

  • Unicode edge cases — some locale-specific letters have special case-folding rules; test international text when it matters.
  • Not for passwords — case-insensitive matching is wrong for secrets; keep passwords case-sensitive.
  • Performance — ignoreCase adds a small cost; for simple ASCII checks it is usually negligible.
  • Replacement casingi finds any case but does not preserve original casing in replacements unless you use a function callback.
  • Immutable flags — create a new RegExp to toggle case sensitivity; you cannot set regex.ignoreCase = true.

🧠 How Case-Insensitive Matching Works

1

Create with i

ignoreCase becomes true at construction time.

/pat/i
2

Compare letters

For each letter in the pattern, the engine matches either uppercase or lowercase forms.

Fold case
3

Other chars unchanged

Digits, spaces, and symbols still must match exactly.

Exact
4

Match or continue

Letters match any case → success. Non-letters must still align.

📝 Notes

  • ignoreCase is read-only—flags are fixed at creation.
  • The i flag applies to the entire pattern, not just one character.
  • Combine with g for all matches: /word/gi.
  • regex.flags lists all flags; regex.ignoreCase is the boolean for i alone.
  • Review global for the g flag and (x|y) for alternation.
  • Next up: \b word boundary metacharacter.

Browser & Runtime Support

The ignoreCase property on RegExp instances is part of standard JavaScript and is supported in all modern environments.

Baseline · ES3+

RegExp ignoreCase

Supported everywhere RegExp is available. The i flag and ignoreCase property behave consistently across browsers and Node.js.

99% Universal API
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
RegExp.ignoreCase Excellent

Bottom line: Safe everywhere. Use the i flag whenever letter case should not block a match.

Conclusion

The ignoreCase property tells you whether a RegExp ignores letter case. Turn it on with the i flag to match Hello, HELLO, and hello with one pattern.

Pair i with g for global case-insensitive scans, and remember that flags are set only at creation time. Next, learn the \b word boundary metacharacter for precise whole-word matching.

💡 Best Practices

✅ Do

  • Add i when user input casing varies
  • Use gi to find and replace all case variants
  • Check regex.ignoreCase when debugging dynamic regexes
  • Prefer /word/i over manual [Ww][Oo]...
  • Build flags strings like "gi" in new RegExp()

❌ Don’t

  • Use i for password or secret comparison
  • Try to toggle ignoreCase after creation
  • Assume i affects digits or punctuation
  • Forget g when you need every case variant found
  • Expect replacement text to mirror original casing automatically

Key Takeaways

Knowledge Unlocked

Five things to remember about RegExp ignoreCase

Match letters regardless of uppercase or lowercase.

5
Core concepts
🔄 02

Property

.ignoreCase

Read
📈 03

gi combo

All cases.

Pattern
🛠 04

Letters

Only A/a.

Scope
🔒 05

Fixed

Read-only.

Flags

❓ Frequently Asked Questions

A read-only boolean on a RegExp instance. It is true when the pattern was created with the i (ignoreCase) flag, meaning letter matching ignores uppercase vs lowercase differences.
Use a literal with i: /pattern/i, or the constructor: new RegExp('pattern', 'i'). The ignoreCase property reflects that flag at creation time.
No. The i flag only affects letters (and some Unicode letter-like characters per the engine). Digits, spaces, and punctuation match the same with or without i.
Yes. Use gi or ig in the flags string: /error/gi matches ERROR, Error, and error everywhere in a string.
Similar for one letter, but ignoreCase applies to the entire pattern. /hello/i is simpler than /[Hh][Ee][Ll][Ll][Oo]/ and scales better for longer words.
No. Flags are fixed when the object is created. To toggle case sensitivity, build a new RegExp with or without i in the flags string.
Did you know?

String methods like includes(), startsWith(), and indexOf() also accept a case-insensitive mode in modern JavaScript, but RegExp with the i flag remains the standard tool when you need full pattern power—groups, anchors, and quantifiers—without caring about case.

Continue to \b word boundary

Learn how the \b metacharacter matches positions between words and non-word characters.

\b 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