liveBook · Manning

Metacharacter

As explained in Secrets of the JavaScript Ninja, Third Edition

A regex metacharacter is a character with special syntactic meaning in a regular expression.

A regex metacharacter has special syntactic meaning; other characters are treated literally. The metacharacters are \^$.|?*+()[]{}. section 12.2.2

In `/test/`, each letter is a literal term, and the terms must appear in sequence. Escape a metacharacter with a backslash when you want to match it literally. JavaScript strings also use backslash escaping, so regex escapes need an extra backslash in string form; regex literals avoid that extra layer. section 12.2.2

Literal terms in sequence

`/test/` matches the sequence `t`, `e`, `s`, `t`. By contrast, `[az]{5}` uses a character class and a repetition operator to match five consecutive `a` or `z` characters. section 12.2.2

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Defines the metacharacter set and explains escaping, while leaving each character’s individual meaning for later treatment.
Examples
Uses `/test/` and `[az]{5}` to illustrate literal sequences, character classes, and repetition.
What you can do after
Apply escaping to match special characters literally and distinguish regex literals from string-based patterns.
How it connects
Connects metacharacters to regex terms, operators, character classes, and escaping.

Also explained in

Compare how 2 books explain metacharacter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.