JavaScript RegExp ignoreCase Property

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

What Is ignoreCase?

ignoreCase is a read-only boolean on a RegExp object. It is true when the pattern was created with the i flag — so letter matching ignores uppercase vs lowercase.

Remember
/hello/.test("HELLO")   → false  (case-sensitive)
/hello/i.test("HELLO")  → true   (ignoreCase)

/hello/.ignoreCase      → false
/hello/i.ignoreCase     → true

new RegExp("ok", "i").ignoreCase  → true

// i affects letters — not digits or symbols
UsePrefer
Case-insensitive match/pattern/i or i flag
Check if i is onregex.ignoreCase
Find all, ignore case/pattern/gi

How to Use ignoreCase

Add the i flag when you create the regex, then read .ignoreCase if you need to inspect it.

  1. Write /pattern/i (or new RegExp("pattern", "i")).
  2. Use test() or match() — letters match either case.
  3. Read regex.ignoreCase to confirm the flag is set.
  4. Combine with g as /pattern/gi when you need every match.
PieceRequired?Role
Flag iYes (for ignore case)Turns on case-insensitive letter matching
.ignoreCaseRead-onlytrue if i was set at creation
Flag gOptionalFind every match (gi)

Pseudocode

Pseudocode
if regex has flag i:
    ignoreCase = true
    when matching letters:
        treat "A" and "a" as the same
else:
    ignoreCase = false
    "A" and "a" are different

// digits and most symbols stay unchanged either way

Cheat Sheet

Keep these facts handy while writing case-insensitive patterns.

TopicDetail
Propertyregex.ignoreCase → true / false
Flagi in /pat/i or new RegExp(pat, "i")
DefaultCase-sensitive (ignoreCase === false)
With global/pat/gi
Mutable?No — create a new RegExp to change flags
StandardCore regex (ES3+) — universal support

Live Preview

Compare /error/ vs /error/i on a sample string.

Browser demo of case-sensitive vs /i — same idea as the examples below.

Result
text = "ERROR found"
/error/.test(text)   → false
/error/i.test(text)  → true

/error/.ignoreCase   → false
/error/i.ignoreCase  → true

JavaScript Examples

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

Example 1 — Case-Sensitive vs /i

Compare the same pattern with and without the ignore-case flag.

JavaScript
const text = "Hello World";

console.log(/hello/.test(text));   // false
console.log(/hello/i.test(text));  // true
console.log(/WORLD/i.test(text));  // true
Try It Yourself

How It Works

  1. Default. Without i, h must match lowercase h — "Hello" fails.
  2. With i. /hello/i treats H and h as equal → true.
  3. Pattern case. The letters in the pattern can be upper or lower; i still matches.
  4. Use case. Search user text, log messages, or titles without caring about casing.

Example 2 — Find All Matches with /gi

Combine global and ignore-case to collect every hit in any casing.

JavaScript
const text = "Error ERROR error";

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

How It Works

  1. Global only. /error/g finds only the exact lowercase word.
  2. gi together. i ignores case; g finds every occurrence.
  3. Original casing kept. Matches keep the text as it appeared in the string.
  4. No hits. "warn" is not present → null.

Example 3 — Read the ignoreCase Property

Inspect the flag on literals and constructor-built patterns.

JavaScript
const a = /ok/;
const b = /ok/i;
const c = new RegExp("ok", "i");

console.log(a.ignoreCase);  // false
console.log(b.ignoreCase);  // true
console.log(c.ignoreCase);  // true
console.log(b.flags);       // "i"
Try It Yourself

How It Works

  1. No flag. /ok/ is case-sensitive → ignoreCase is false.
  2. Literal i. /ok/i sets the property to true.
  3. Constructor. Pass "i" as the second argument for the same effect.
  4. flags string. .flags lists active flags; here just "i".

Edge Cases & Pitfalls

Check these before relying on ignoreCase in real projects.

fixed

Flags cannot be changed later

ignoreCase is read-only. To switch modes, create a new RegExp with or without i.

scope

Letters, not everything

The i flag does not make digits or symbols “flexible.” /1/ and /1/i behave the same for numbers.

unicode

Unicode case folding can surprise

Most Latin letters work as expected. Some Unicode characters need the u flag and careful testing for full case folding.

intent

Do not always use i

Passwords, codes, and case-sensitive IDs should stay case-sensitive. Add i only when case truly does not matter.

Browser & Runtime Support

The i flag and RegExp.prototype.ignoreCase are core JavaScript regular-expression features (ES3+) and work everywhere.

✓ Baseline · ES3+

RegExp ignoreCase

Supported in all evergreen browsers, Internet Explorer, and every current Node.js / Deno / Bun release.

100% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 4+ · Legacy environments
Full support
Opera All 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
ignoreCase Universal

Bottom line: Safe everywhere. Use /pattern/i for case-insensitive letters; read .ignoreCase to inspect the flag.

Performance Notes

ApproachCostBest for
/pat/i.test(s)O(n)Quick case-insensitive check
s.match(/pat/gi)O(n)Collect every case variant
regex.ignoreCaseO(1)Inspect the flag

The i flag adds negligible cost for typical patterns. Prefer test when you only need a yes/no answer.

Key Takeaways

  • Role: ignoreCase is true when the i flag is set.
  • Create: Use /pattern/i or new RegExp("pattern", "i").
  • Combine: /pattern/gi finds every match in any letter case.
  • Fixed: Flags are set at creation — build a new RegExp to change them.

One line: ignoreCase means the i flag is on — letters match without caring about upper vs lower case.

Frequently Asked Questions

A read-only boolean on a RegExp instance. It is true when the pattern was created with the i (ignoreCase) flag, so 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 mainly affects letters. Digits, spaces, and punctuation match the same with or without i.
Yes. Use gi or ig: /error/gi matches ERROR, Error, and error everywhere in a string.
Similar for one letter, but ignoreCase applies to the whole 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.

Next: \b

Learn word boundaries so patterns match whole words, not substrings inside longer words.

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

13 people found this page helpful