liveBook · Manning

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.

How 2 Manning books explain it

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, 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 →

Related concepts

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.