What is a Regular Expression?
A regular expression is a flexible way of defining patterns of text. It is a formal language which is interpreted by a regular expression engine (which might be part of an application or a programming language) that parses input text and compares it to the regular expression, and then performs operations on text that matches the regular expression.
Common uses of regular expressions include:
- Matching text
- Substituting text
- Extracting text
The basic syntax of a regular expression is
/pattern/flags. The main part is the text pattern description, and the flags control the behaviour of the regular expression engine.
Different regular expression engines support different features, and also slightly vary in their syntax. After a overview of general regexp syntax we will look at some common applications and languages and how they support regular expressions.