Match method
String.prototype.match is a JavaScript string method that matches a string against a regular expression and returns match information or null if no match is found.
The Well-Grounded Rubyist, Fourth Edition
A match is an operation that tests whether text satisfies a regular expression and may return information about the match.
- How it is used
- Tests strings against regular expressions when code needs either a conditional result or details of a successful match.
- How deep it goes
- Works through success, failure, captures, and result access, without descending into the matching engine.
- Examples
- Uses a captured phone number, a conditional search for `la`, and an array filter for long strings containing digits.
- What you can do after
- Apply it via Ruby’s `Regexp#match` to guard failed searches and retrieve matched text and captures.
Read how The Well-Grounded Rubyist, Fourth Edition explains match method →
Secrets of the JavaScript Ninja, Third Edition
String.prototype.match is a JavaScript String method that retrieves the result of matching a string against a regular expression.
- How it is used
- Retrieves matching text and captures from a string when a yes-or-no regex test is not enough.
- How deep it goes
- Explains result arrays for local and global regexes, including when captures are omitted and matchAll is useful.
- Examples
- Uses a digit pattern to extract 9000 and a global pattern to extract names and clans.
- What you can do after
- Apply `match()` to retrieve full matches and captures, and choose `matchAll()` when global captures are needed.
Read how Secrets of the JavaScript Ninja, Third Edition explains match method →
Secrets of the JavaScript Ninja, Second Edition
A JavaScript method that searches a string with a regular expression and returns match information.
- How it is used
- Uses regular-expression searches to determine whether a string matches and retrieve matching text or captures.
- How deep it goes
- Explains result arrays for local and global searches, including capture behavior, and defers referencing captures within the regex.
- Examples
- Uses an HTML string to compare matching tags locally and globally, then searches them with exec.
- What you can do after
- Understand how local and global regular-expression searches differ in returned matches and captures.
Read how Secrets of the JavaScript Ninja, Second Edition explains match method →
What to know first
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
Related concepts
- MatchDataproduces · MatchData is a Ruby object containing the results, captured substrings, and locations associated with a regular-expression match.
- missing valueproduces · A missing value is an expected data value or observation that is absent, unavailable, unknown, or inapplicable.
- regular expressionuses · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- arrayproduces · An array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- regex groupingcontrasts with · A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
- global regular expressionused by · A JavaScript regular expression with the g flag, which enables successive matching across a string.
Questions about match method
What is match method?
String.prototype.match is a JavaScript string method that matches a string against a regular expression and returns match information or null if no match is found.
Which Manning books explain match method?
The Well-Grounded Rubyist, Fourth Edition, Secrets of the JavaScript Ninja, Third Edition and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning match method?
Manning books that teach match method usually introduce regular expression first.
What is the difference between match method and regex grouping?
String.prototype.match is a JavaScript string method that matches a string against a regular expression and returns match information or null if no match is found. A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


