Regular expressions provide a powerful, flexible, and efficient method for processing text. In simplest terms, a regular expression is a set of characters that specify a pattern.
Regular expressions can be used to:
- Quickly parse large amounts of text to find a specific character pattern
- Validate text to ensure that it matches a predefined pattern (such as a phone number)
- Extract, edit, replace, or delete text
- Add matched strings to a collection
Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns.
Often, the name Regular Expression is abbreviated to "regex" or "regexp."
A regular expression engine, is the software that parses the regular expression, examines text, and identifies matches according to the language specification.
Processing text using regular expressions requires that the engine be provided with at least two items of information:
- The regular expression pattern to identify in the text
- The text to parse for the regular expression pattern
The following table lists a few basic terms that are worth defining dealing with regular expressions:
|search expression||The expression used to search a target string, ie. the pattern to be found|
|target string||The string being searched, ie. the string in which to find the search expression|
|literal||Any character used in a search expression|
|metacharacter||One or more special characters that have a unique meaning and are NOT used as a literal in the search expression|
|escape sequence||A way of indicating that you want to use a metacharacter as a literal|