JavaScript Match
match() runs a regular expression against the string and returns the matches (or null when nothing matches). It is the entry point to pattern extraction. Capturing groups, digits, words, anything a regex can describe.
Syntax
str.match(regex) Examples
| Input | Arguments | Output |
|---|---|---|
| "a1b2c3" | "[0-9]" | ["1"] |
| ↳ Without the /g flag, only the first match is returned. | ||
Gotchas
- Returns null (not []) when there is no match. Check before iterating.
Try it live
Type your input and see Match transform it instantly.
Want to go further? Chain Match with other functions, pipe one output into the next and watch your data transform in the visual Playground.