Regular expression or Regex (also regexp) is a notation system for describing a search pattern defined by a sequence of characters. It is primarily used for search and replace, data validation and string parsing. Regex is based on formal language theory and consists of constants (called “literal characters”) which define sets of strings and operator symbols (called “meta-characters”) which define operations to be performed on these sets.
Technipages Explains Regular Expression (Regexp)
A singular search term is called a regular expression or pattern, it is used to match a single or set of strings as required for a purpose, there are multiple ways to define a pattern that will match identical strings.
Inside each pattern, there are literal characters such as “a” which literally mean what the character says be it a digit, letter or symbol. Meta-characters such as “{“ which have a defined meaning, this may change how related characters are interpreted, act as a type of wildcard or define a subexpression etc. Finally, there is the escape character “\” which is used to turn a meta-character into a literal character.
There are two sets of standards for regex: “Perl compatible” which is based on an implementation of Regex in the language Perl which is known for its expressive power and relative ease of reading. The other standard is “IEEE POSIX” which has two flavours the extended flavour adds 3 meta-characters and modifies how others work compared to the basic flavour.
The mathematician Stephen Cole first described regular languages in a mathematical notation he called “regular events” in 1951, in 1968 regular expression gained mainstream traction in text editors for pattern matching and in compilers. Since then Regex has been implemented in many different programming languages and advanced text editors, a number of standard regex libraries are readily available for reuse.
Common Uses of Regular Expression (Regexp)
- The syntax for regular expression is complex.
- Regular expression is a powerful find and replace tool.
- Regex has two sets of standards used for different purposes.
Common Misuses of Regular Expression (Regexp)
- Regular expression is a programming language.