String.match() Match with a regex
Last updated: 2026-09-09
String.match() Match with a regex
match extracts regex matches; with g flag returns all matches as an array.
| Category | Strings |
|---|---|
| ES version | ES1 |
📝 Syntax
const result = str.match(regex);
⚙️ Parameters
| regex | A regex object; g flag changes the return shape. |
|---|
Returns:Array of matches or a match object, or null.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[ '100', '250' ]
2026 09 09
💡 Tip Use /regex/.test(str) for existence; match for extraction.
⚠️ Warning match returns null on no match — guard before indexing.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| String.match() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qmatch with vs without g flag?
AWith g: array of all matched strings. Without: detail object with index and groups.
Qmatch vs matchAll?
AmatchAll (ES2020) yields full match objects with capture groups.
QHow to handle null?
Aconst m = str.match(re); const val = m && m[0]; or m?.[0].