String.prototype.match(regexp) matches a string against a regular expression and returns an array of results, or null if nothing matches. The array shape depends on the g flag. Need every match with groups? Prefer matchAll().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.match. Start with this line.
JavaScript
str.match(regexp)
Call
What it does
str.match(regexp)
Primary signature.
string.match(...)
Call with the arguments your case needs.
Built into JavaScript. Call match(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
str.match(regexp)
Parameters
Parameter
Description
regexp
Required. Pattern; strings are coerced to RegExp
g flag
Optional. All full matches vs first match + groups
Return Value
Return Value
Description
*
Array or null
JavaScript Examples
Example 1 — Global match()
Find every uppercase letter with the g flag.
JavaScript
const paragraph = "The quick brown fox jumps over the lazy dog. It barked.";
const found = paragraph.match(/[A-Z]/g);
console.log(found);
// ["T", "I"]
g finds every match. The scan continues after each hit.
i ignores case. Both A and a qualify.
Character class.[a-e] is the range of letters to keep.
Result is flat. Global mode returns full matches only — use matchAll for groups on every hit.
Compatibility
Browser & Runtime Support
String.prototype.match() is a long-standing language feature. It works in every modern browser, Internet Explorer, and every current Node.js / Deno / Bun release.
✓ Baseline · Widely available
String.prototype.match()
Supported in all evergreen browsers, Internet Explorer (legacy), and every current JavaScript runtime. Named capturing groups need modern engines (ES2018+).
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium & Legacy
Full support
Internet ExplorerIE 4+ · Legacy (no named groups)
Full support
OperaAll modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
String.match()Universal
Bottom line: Safe everywhere for basic matching. Prefer matchAll() when you need every match with groups. Named groups require a modern runtime.
Frequently Asked Questions
match(regexp) returns the result of matching the string against a regular expression: an Array of matches (shape depends on the g flag), or null if nothing matches.
With g, you get an array of all full matches (no capturing groups). Without g, you get the first match plus capturing groups, index, and input — similar to RegExp.prototype.exec().
When there is no match. Always check for null before reading array indexes.
With the g flag, match() does not include groups. Use String.prototype.matchAll() or loop with RegExp.prototype.exec() instead.
It is converted with new RegExp(string). Special characters like . mean “any character” unless you escape them (for example 1\.3).
No. Strings are immutable. match() only reads and returns an array or null.