regular expression
A regular expression^{} is a particular metasyntax for specifying regular grammars, which has many useful applications.
While variations abound, fundamentally a regular expression consists of the following pieces:

•
Parentheses can be used for grouping and nesting, and must contain a fullyformed regular expression.

•
The

symbol can be used for denoting alternatives. Some specifications do not provide nesting or alternatives.  •

•
The
*
operator means that the preceding element can be present zero or more times, and corresponds to a rule of the form $A\to BA\lambda $. 
•
The
+
operator means that the preceding element can be present one or more times, and corresponds to a rule of the form $A\to BAB$.
Note that while these rules are not immediately in regular^{} form, they can be transformed so that they are.
Formally, let $S=\{\mathrm{\varnothing},\cup {,}^{*},(,)\}$ and $\mathrm{\Sigma}$ an alphabet disjoint from $S$. Consider the language^{} $L(\mathrm{\Sigma})$ over $\mathrm{\Sigma}\cup S$ specified below

1.
$\mathrm{\varnothing}\in L(\mathrm{\Sigma})$,

2.
$a\in L(\mathrm{\Sigma})$ for each $a\in \mathrm{\Sigma}$,

3.
if $u\in L(\mathrm{\Sigma})$, then ${u}^{*}\in L(\mathrm{\Sigma})$,

4.
if ${u}_{1},{u}_{2}\in L(\mathrm{\Sigma})$, then $({u}_{1}\cup {u}_{2})$ and $({u}_{1}{u}_{2})$ are both in $L(\mathrm{\Sigma})$, and

5.
among all languages over $\mathrm{\Sigma}\cup S$ satisfying conditions 14, $L(\mathrm{\Sigma})$ is the smallest.
Then any element $u\in L(\mathrm{\Sigma})$ is called a regular expression over $\mathrm{\Sigma}$.
Here is an example of a regular expression that specifies a grammar^{} that generates the binary representation of all multiples of 3 (and only multiples of 3).
$${({0}^{*}{(1{({01}^{*}0)}^{*}1)}^{*})}^{*}{0}^{*}$$ 
This specifies the contextfree grammar (in BNF):
$S$  $\text{::=}$  $AB$  
$A$  $\text{::=}$  $CD$  
$B$  $\text{::=}$  $\text{0}B\lambda $  
$C$  $\text{::=}$  $\text{0}C\lambda $  
$D$  $\text{::=}$  $\text{1}E\mathrm{\U0001d7f7}$  
$E$  $\text{::=}$  $FE\lambda $  
$F$  $\text{::=}$  $\text{0}G\mathrm{\U0001d7f6}$  
$G$  $\text{::=}$  $\text{1}G\lambda $ 
A little further work is required to transform this grammar into an acceptable form for regular grammars, but it can be shown that this grammar (and any grammar specified by a regular expression) is equivalent^{} to some regular grammar.
One can understand the language described by a regular expression in another way, by viewing the regular expression operators as shorthand for various settheoretic operations^{}. Formally, the language $L\mathit{}\mathrm{(}u\mathrm{)}$ over $\mathrm{\Sigma}$ associated with a regular expression $u$ over $\mathrm{\Sigma}$ is inductively defined as follows:

•
$L(\mathrm{\varnothing})=\mathrm{\varnothing}$,

•
$L(a)=\{a\}$ whenever $a\in \mathrm{\Sigma}$,

•
$L({u}^{*})=L{(u)}^{*}$, where the ${}^{*}$ on the right side is the Kleene star operation on sets,

•
$L(({u}_{1}{u}_{2}))=L({u}_{1})L({u}_{2})$, where the right side denotes the concatenation^{} of two sets, and

•
$L(({u}_{1}\cup {u}_{2}))=L({u}_{1})\cup L({u}_{2})$, where $\cup $ on the right side is the union operation on sets.
A language $L$ over $\mathrm{\Sigma}$ is regular iff there is a regular expression $u$ over $\mathrm{\Sigma}$ such that $L=L(u)$.
With this interpretation^{}, it is quite straightforward to design a nondeterministic finite automaton that recognizes the language described by a regular expression. Of course, for computer implementations, one must transform this into a deterministic finite automaton, but there are various algorithms^{} for doing this efficiently. This process, production of a nondeterministic automaton and conversion to an equivalent deterministic automaton is approximately what is done in software packages implementing regular expression searching. In fact, most such packages implement operations impossible for a finite automaton, such as requiring a later part of the string to be the same as a previous part (the language $\{{A}^{n}B{A}^{n}\text{for}n\ge 0\}$ is not regular but can be matched by most “regular expression” software; such capabilities are called “extended regular expressions”. None of these systems are powerful enough to recognize the language of balanced parentheses.
Regular expressions have many applications. Quite often they are used for powerful string matching and substitution features in many text editors and programming languages.
Title  regular expression 

Canonical name  RegularExpression 
Date of creation  20130322 12:26:56 
Last modified on  20130322 12:26:56 
Owner  CWoo (3771) 
Last modified by  CWoo (3771) 
Numerical id  17 
Author  CWoo (3771) 
Entry type  Definition 
Classification  msc 20M35 
Classification  msc 68Q70 
Related topic  RegularLanguage 
Related topic  KleeneStar 
Related topic  KleeneAlgebra 