liveBook · Manning

Global regular expression

A JavaScript regular expression with the g flag, which enables successive matching across a string.

How 2 Manning books explain it

Secrets of the JavaScript Ninja, Third Edition

A regular expression configured to find successive matches throughout its input.

How it is used
Finds successive matches across a string rather than stopping after one match.
How deep it goes
Defines the g flag, contrasts local and global stopping behavior, and names matching methods without detailing engine internals.
Examples
Shows /test/ig and new RegExp("test", "ig") as ways to specify flags.
What you can do after
Apply it via String.prototype.matchAll to retrieve repeated matches, or replace to transform each match.

Read how Secrets of the JavaScript Ninja, Third Edition explains global regular expression →

Secrets of the JavaScript Ninja, Second Edition

A regular expression with the g flag, enabling successive searches for matches in a string.

How it is used
Finds all matches in a candidate string when one match is not enough.
How deep it goes
Compares global and local `match` results and explains stateful repeated `exec` calls, but stops short of using captures within a regex.
Examples
Uses HTML tags to contrast local and global matches and demonstrate capturing during a global search.
What you can do after
Apply it via `String.match` for a list of matches or repeated `RegExp.exec` calls when captures are needed.

Read how Secrets of the JavaScript Ninja, Second Edition explains global regular expression →

Related concepts

Questions about global regular expression

What is global regular expression?

A JavaScript regular expression with the g flag, which enables successive matching across a string.

Which Manning books explain global regular expression?

Secrets of the JavaScript Ninja, Third Edition and Secrets of the JavaScript Ninja, Second Edition.

What is the difference between global regular expression and local regular expression?

A JavaScript regular expression with the g flag, which enables successive matching across a string. A regular expression configured to return at most one match in a matching operation.

What is global regular expression a kind of?

Global regular expression is a kind of regular expression. A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.

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.