Topic
Regular expressions
Regular expressions are pattern descriptions used by software to search, validate, split, or transform text according to a defined regex syntax.
At a glance
- Common abbreviation
- regex
- Typical uses
- Search, validation, extraction, replacement
Overview
A regular expression describes a text pattern using literal characters and operators for alternatives, repetition, character classes, groups, and positions. Regex dialects differ between programming environments, so a pattern that works in one engine may need changes in another. For complex structured formats, a dedicated parser can be safer and easier to maintain than a single large expression.
Patterns combine literals and operators
A simple expression can match exact text, while classes and quantifiers describe families of strings. Capturing groups can expose matched subparts for later use, and anchors can constrain where a match begins or ends.
Validation needs context
A regex can establish that text has a particular shape, but it does not automatically prove that the value is meaningful or authorized. Applications often need additional checks such as numeric ranges, existence in a database, canonical parsing, or permission checks.
Sources and review
MOOR's explanatory text is supported by the following source links.
- Regular expressions — MDN Web Docs
- ECMAScript text processing and regular expressions — Ecma International