Regular expression literal
A regular expression literal is source-language syntax that directly represents a regular expression pattern, often with optional flags or modifiers.
Secrets of the JavaScript Ninja, Third Edition
JavaScript literal syntax that creates a regular expression using slash delimiters and optional flags.
- How it is used
- Creates string-matching patterns directly in JavaScript and serves as the preferred form when the pattern is not built dynamically.
- How deep it goes
- Explains delimiters, flags, and escaping tradeoffs, while leaving regex operators and matching behavior to broader treatment.
- Examples
- Shows /test/ and a dynamically assembled file-extension pattern for .ts or .js.
- What you can do after
- Build regexes with slash-delimited literals and trailing flags, choosing RegExp construction when runtime input determines the pattern.
Read how Secrets of the JavaScript Ninja, Third Edition explains regular expression literal →
The Well-Grounded Rubyist, Fourth Edition
A regexp literal is Ruby syntax that directly represents a regular expression between delimiters, optionally followed by modifiers.
- How it is used
- Creates Regexp objects inline for testing, locating, and extracting patterns from strings.
- How deep it goes
- Explains slash and percent delimiters, matching results, and modifiers, but defers exhaustive regular-expression syntax.
- Examples
- Uses /abc/, %r{} and %r(abc)i, multiline phone-number patterns, and collections-report extraction exercises.
- What you can do after
- Apply it via Ruby to test strings, obtain match positions or MatchData, and format complex patterns with modifiers.
Read how The Well-Grounded Rubyist, Fourth Edition explains regular expression literal →
Secrets of the JavaScript Ninja, Second Edition
JavaScript source syntax that specifies a regular-expression pattern between slash delimiters, optionally followed by flags.
- How it is used
- Specifies a regular-expression pattern known at development time for JavaScript matching.
- How deep it goes
- Defines slash delimiters and trailing flags, then tests recognition and basic matching; it does not offer an exhaustive regex tutorial.
- Examples
- Uses /test/, /test/g, /hello/, and patterns with character sets, groups, and backreferences in recognition and matching exercises.
- What you can do after
- Practice/perform identifying literals, recognizing flags, and predicting matches for basic patterns.
Read how Secrets of the JavaScript Ninja, Second Edition explains regular expression literal →
What to know first
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
- 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
- regular expressionproduces · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- JavaScriptused by · JavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
- RegExp constructoralternative to · The RegExp constructor is the JavaScript built-in constructor that creates regular expression objects from a pattern and optional flags.
- string literalcontrasts with · A string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
- literalkind of · A literal is a language construct that directly denotes a fixed value or specifies an exact value permitted by a type.
Questions about regular expression literal
What is regular expression literal?
A regular expression literal is source-language syntax that directly represents a regular expression pattern, often with optional flags or modifiers.
Which Manning books explain regular expression literal?
Secrets of the JavaScript Ninja, Third Edition, The Well-Grounded Rubyist, Fourth Edition and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning regular expression literal?
Manning books that teach regular expression literal usually introduce string and regular expression first.
What is the difference between regular expression literal and RegExp constructor?
A regular expression literal is source-language syntax that directly represents a regular expression pattern, often with optional flags or modifiers. The RegExp constructor is the JavaScript built-in constructor that creates regular expression objects from a pattern and optional flags.
What is regular expression literal a kind of?
Regular expression literal is a kind of literal. A literal is a language construct that directly denotes a fixed value or specifies an exact value permitted by a type.
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.


