<s>
A	O
regular	B-Language
expression	I-Language
(	O
shortened	O
as	O
regex	B-Language
or	O
regexp	B-Language
;	O
sometimes	O
referred	O
to	O
as	O
rational	O
expression	O
)	O
is	O
a	O
sequence	O
of	O
characters	O
that	O
specifies	O
a	O
match	B-Language
pattern	I-Language
in	O
text	O
.	O
</s>
<s>
Usually	O
such	O
patterns	O
are	O
used	O
by	O
string-searching	B-Algorithm
algorithms	I-Algorithm
for	O
"	O
find	O
"	O
or	O
"	O
find	O
and	O
replace	O
"	O
operations	O
on	O
strings	O
,	O
or	O
for	O
input	O
validation	O
.	O
</s>
<s>
Regular	B-Language
expression	I-Language
techniques	O
are	O
developed	O
in	O
theoretical	O
computer	O
science	O
and	O
formal	O
language	O
theory	O
.	O
</s>
<s>
The	O
concept	O
of	O
regular	B-Language
expressions	I-Language
began	O
in	O
the	O
1950s	O
,	O
when	O
the	O
American	O
mathematician	O
Stephen	O
Cole	O
Kleene	O
formalized	O
the	O
concept	O
of	O
a	O
regular	B-General_Concept
language	I-General_Concept
.	O
</s>
<s>
They	O
came	O
into	O
common	O
use	O
with	O
Unix	B-Application
text-processing	O
utilities	O
.	O
</s>
<s>
Different	O
syntaxes	B-Application
for	O
writing	O
regular	B-Language
expressions	I-Language
have	O
existed	O
since	O
the	O
1980s	O
,	O
one	O
being	O
the	O
POSIX	O
standard	O
and	O
another	O
,	O
widely	O
used	O
,	O
being	O
the	O
Perl	B-Language
syntax	B-Application
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
are	O
used	O
in	O
search	B-Application
engines	I-Application
,	O
in	O
search	O
and	O
replace	O
dialogs	O
of	O
word	B-General_Concept
processors	I-General_Concept
and	O
text	B-Application
editors	I-Application
,	O
in	O
text	B-Device
processing	I-Device
utilities	O
such	O
as	O
sed	B-Application
and	O
AWK	B-Application
,	O
and	O
in	O
lexical	B-Application
analysis	I-Application
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
are	O
supported	O
in	O
many	O
programming	O
languages	O
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
originated	O
in	O
1951	O
,	O
when	O
mathematician	O
Stephen	O
Cole	O
Kleene	O
described	O
regular	B-General_Concept
languages	I-General_Concept
using	O
his	O
mathematical	O
notation	O
called	O
regular	O
events	O
.	O
</s>
<s>
These	O
arose	O
in	O
theoretical	O
computer	O
science	O
,	O
in	O
the	O
subfields	O
of	O
automata	B-Application
theory	I-Application
(	O
models	O
of	O
computation	O
)	O
and	O
the	O
description	O
and	O
classification	O
of	O
formal	O
languages	O
.	O
</s>
<s>
Other	O
early	O
implementations	O
of	O
pattern	B-Language
matching	I-Language
include	O
the	O
SNOBOL	B-Application
language	O
,	O
which	O
did	O
not	O
use	O
regular	B-Language
expressions	I-Language
,	O
but	O
instead	O
its	O
own	O
pattern	B-Language
matching	I-Language
constructs	O
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
entered	O
popular	O
use	O
from	O
1968	O
in	O
two	O
uses	O
:	O
pattern	B-Language
matching	I-Language
in	O
a	O
text	B-Application
editor	I-Application
and	O
lexical	B-Application
analysis	I-Application
in	O
a	O
compiler	B-Language
.	O
</s>
<s>
Among	O
the	O
first	O
appearances	O
of	O
regular	B-Language
expressions	I-Language
in	O
program	O
form	O
was	O
when	O
Ken	O
Thompson	O
built	O
Kleene	O
's	O
notation	O
into	O
the	O
editor	O
QED	B-Application
as	O
a	O
means	O
to	O
match	O
patterns	O
in	O
text	B-General_Concept
files	I-General_Concept
.	O
</s>
<s>
For	O
speed	O
,	O
Thompson	O
implemented	O
regular	B-Language
expression	I-Language
matching	O
by	O
just-in-time	O
compilation	B-Language
(	O
JIT	O
)	O
to	O
IBM	B-Device
7094	I-Device
code	O
on	O
the	O
Compatible	B-Operating_System
Time-Sharing	I-Operating_System
System	I-Operating_System
,	O
an	O
important	O
early	O
example	O
of	O
JIT	O
compilation	B-Language
.	O
</s>
<s>
He	O
later	O
added	O
this	O
capability	O
to	O
the	O
Unix	B-Application
editor	O
ed	B-Application
,	O
which	O
eventually	O
led	O
to	O
the	O
popular	O
search	O
tool	O
grep	B-Application
's	O
use	O
of	O
regular	B-Language
expressions	I-Language
(	O
"	O
grep	B-Application
"	O
is	O
a	O
word	O
derived	O
from	O
the	O
command	O
for	O
regular	B-Language
expression	I-Language
searching	O
in	O
the	O
ed	B-Application
editor	O
:	O
g/re/p	B-Application
meaning	O
"	O
Global	O
search	O
for	O
Regular	B-Language
Expression	I-Language
and	O
Print	O
matching	O
lines	O
"	O
)	O
.	O
</s>
<s>
Around	O
the	O
same	O
time	O
when	O
Thompson	O
developed	O
QED	B-Application
,	O
a	O
group	O
of	O
researchers	O
including	O
Douglas	O
T	O
.	O
Ross	O
implemented	O
a	O
tool	O
based	O
on	O
regular	B-Language
expressions	I-Language
that	O
is	O
used	O
for	O
lexical	B-Application
analysis	I-Application
in	O
compiler	B-Language
design	O
.	O
</s>
<s>
Many	O
variations	O
of	O
these	O
original	O
forms	O
of	O
regular	B-Language
expressions	I-Language
were	O
used	O
in	O
Unix	B-Application
programs	O
at	O
Bell	O
Labs	O
in	O
the	O
1970s	O
,	O
including	O
vi	B-Application
,	O
lex	B-General_Concept
,	O
sed	B-Application
,	O
AWK	B-Application
,	O
and	O
expr	B-Application
,	O
and	O
in	O
other	O
programs	O
such	O
as	O
Emacs	B-Application
(	O
which	O
has	O
its	O
own	O
,	O
incompatible	O
syntax	B-Application
and	O
behavior	O
)	O
.	O
</s>
<s>
Regexes	B-Language
were	O
subsequently	O
adopted	O
by	O
a	O
wide	O
range	O
of	O
programs	O
,	O
with	O
these	O
early	O
forms	O
standardized	O
in	O
the	O
POSIX.2	O
standard	O
in	O
1992	O
.	O
</s>
<s>
In	O
the	O
1980s	O
,	O
the	O
more	O
complicated	O
regexes	B-Language
arose	O
in	O
Perl	B-Language
,	O
which	O
originally	O
derived	O
from	O
a	O
regex	B-Language
library	B-Library
written	O
by	O
Henry	O
Spencer	O
(	O
1986	O
)	O
,	O
who	O
later	O
wrote	O
an	O
implementation	O
of	O
Advanced	O
Regular	B-Language
Expressions	I-Language
for	O
Tcl	B-Operating_System
.	O
</s>
<s>
The	O
Tcl	B-Operating_System
library	B-Library
is	O
a	O
hybrid	O
NFA/DFA	O
implementation	O
with	O
improved	O
performance	O
characteristics	O
.	O
</s>
<s>
Software	O
projects	O
that	O
have	O
adopted	O
Spencer	O
's	O
Tcl	B-Operating_System
regular	B-Language
expression	I-Language
implementation	O
include	O
PostgreSQL	B-Application
.	O
</s>
<s>
Perl	B-Language
later	O
expanded	O
on	O
Spencer	O
's	O
original	O
library	B-Library
to	O
add	O
many	O
new	O
features	O
.	O
</s>
<s>
Part	O
of	O
the	O
effort	O
in	O
the	O
design	O
of	O
Raku	B-Application
(	O
formerly	O
named	O
Perl	B-Application
6	I-Application
)	O
is	O
to	O
improve	O
Perl	B-Language
's	O
regex	B-Language
integration	O
,	O
and	O
to	O
increase	O
their	O
scope	O
and	O
capabilities	O
to	O
allow	O
the	O
definition	O
of	O
parsing	B-Language
expression	O
grammars	O
.	O
</s>
<s>
The	O
result	O
is	O
a	O
mini-language	B-Language
called	O
Raku	B-Language
rules	I-Language
,	O
which	O
are	O
used	O
to	O
define	O
Raku	B-Application
grammar	O
as	O
well	O
as	O
provide	O
a	O
tool	O
to	O
programmers	O
in	O
the	O
language	O
.	O
</s>
<s>
These	O
rules	O
maintain	O
existing	O
features	O
of	O
Perl	B-Language
5.x	O
regexes	B-Language
,	O
but	O
also	O
allow	O
BNF-style	O
definition	O
of	O
a	O
recursive	B-Application
descent	I-Application
parser	I-Application
via	O
sub-rules	O
.	O
</s>
<s>
The	O
use	O
of	O
regexes	B-Language
in	O
structured	O
information	O
standards	O
for	O
document	O
and	O
database	O
modeling	O
started	O
in	O
the	O
1960s	O
and	O
expanded	O
in	O
the	O
1980s	O
when	O
industry	O
standards	O
like	O
ISO	B-Language
SGML	I-Language
(	O
precursored	O
by	O
ANSI	O
"	O
GCA	O
101-1983	O
"	O
)	O
consolidated	O
.	O
</s>
<s>
The	O
kernel	O
of	O
the	O
structure	O
specification	O
language	O
standards	O
consists	O
of	O
regexes	B-Language
.	O
</s>
<s>
Its	O
use	O
is	O
evident	O
in	O
the	O
DTD	B-Language
element	O
group	O
syntax	B-Application
.	O
</s>
<s>
Prior	O
to	O
the	O
use	O
of	O
regular	B-Language
expressions	I-Language
,	O
many	O
search	O
languages	O
allowed	O
simple	O
wildcards	B-Algorithm
,	O
for	O
example	O
"	O
*	O
"	O
to	O
match	O
any	O
sequence	O
of	O
characters	O
,	O
and	O
"	O
?	O
"	O
</s>
<s>
Relics	O
of	O
this	O
can	O
be	O
found	O
today	O
in	O
the	O
glob	B-Language
syntax	B-Application
for	O
filenames	O
,	O
and	O
in	O
the	O
SQL	B-Language
LIKE	O
operator	O
.	O
</s>
<s>
Starting	O
in	O
1997	O
,	O
Philip	O
Hazel	O
developed	O
PCRE	B-Language
(	O
Perl	B-Language
Compatible	I-Language
Regular	I-Language
Expressions	I-Language
)	O
,	O
which	O
attempts	O
to	O
closely	O
mimic	O
Perl	B-Language
's	O
regex	B-Language
functionality	O
and	O
is	O
used	O
by	O
many	O
modern	O
tools	O
including	O
PHP	B-Application
and	O
Apache	B-Application
HTTP	I-Application
Server	I-Application
.	O
</s>
<s>
Today	O
,	O
regexes	B-Language
are	O
widely	O
supported	O
in	O
programming	O
languages	O
,	O
text	B-Device
processing	I-Device
programs	O
(	O
particularly	O
lexers	B-Application
)	O
,	O
advanced	O
text	B-Application
editors	I-Application
,	O
and	O
some	O
other	O
programs	O
.	O
</s>
<s>
Regex	B-Language
support	O
is	O
part	O
of	O
the	O
standard	B-Library
library	I-Library
of	O
many	O
programming	O
languages	O
,	O
including	O
Java	B-Language
and	O
Python	B-Language
,	O
and	O
is	O
built	O
into	O
the	O
syntax	B-Application
of	O
others	O
,	O
including	O
Perl	B-Language
and	O
ECMAScript	B-Language
.	O
</s>
<s>
Implementations	O
of	O
regex	B-Language
functionality	O
is	O
often	O
called	O
a	O
regex	B-Language
engine	O
,	O
and	O
a	O
number	O
of	O
libraries	B-Library
are	O
available	O
for	O
reuse	O
.	O
</s>
<s>
In	O
the	O
late	O
2010s	O
,	O
several	O
companies	O
started	O
to	O
offer	O
hardware	O
,	O
FPGA	B-Architecture
,	O
GPU	B-Architecture
implementations	O
of	O
PCRE	B-Language
compatible	O
regex	B-Language
engines	O
that	O
are	O
faster	O
compared	O
to	O
CPU	B-General_Concept
implementations	O
.	O
</s>
<s>
The	O
phrase	O
regular	B-Language
expressions	I-Language
,	O
or	O
regexes	B-Language
,	O
is	O
often	O
used	O
to	O
mean	O
the	O
specific	O
,	O
standard	O
textual	O
syntax	B-Application
for	O
representing	O
patterns	O
for	O
matching	O
text	O
,	O
as	O
distinct	O
from	O
the	O
mathematical	O
notation	O
described	O
below	O
.	O
</s>
<s>
Each	O
character	O
in	O
a	O
regular	B-Language
expression	I-Language
(	O
that	O
is	O
,	O
each	O
character	O
in	O
the	O
string	O
describing	O
its	O
pattern	O
)	O
is	O
either	O
a	O
metacharacter	B-Algorithm
,	O
having	O
a	O
special	O
meaning	O
,	O
or	O
a	O
regular	O
character	O
that	O
has	O
a	O
literal	O
meaning	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
regex	B-Language
b.	O
,	O
'	O
b	O
 '	O
is	O
a	O
literal	B-Language
character	I-Language
that	O
matches	O
just	O
'	O
b	O
 '	O
,	O
while	O
'	O
.	O
'	O
</s>
<s>
is	O
a	O
metacharacter	B-Algorithm
that	O
matches	O
every	O
character	O
except	O
a	O
newline	O
.	O
</s>
<s>
Therefore	O
,	O
this	O
regex	B-Language
matches	O
,	O
for	O
example	O
,	O
'	O
b%	O
 '	O
,	O
or	O
'	O
bx	O
 '	O
,	O
or	O
'	O
b5	O
 '	O
.	O
</s>
<s>
Together	O
,	O
metacharacters	B-Algorithm
and	O
literal	O
characters	O
can	O
be	O
used	O
to	O
identify	O
text	O
of	O
a	O
given	O
pattern	O
or	O
process	O
a	O
number	O
of	O
instances	O
of	O
it	O
.	O
</s>
<s>
Pattern	B-Language
matches	I-Language
may	O
vary	O
from	O
a	O
precise	O
equality	O
to	O
a	O
very	O
general	O
similarity	O
,	O
as	O
controlled	O
by	O
the	O
metacharacters	B-Algorithm
.	O
</s>
<s>
The	O
metacharacter	B-Algorithm
syntax	B-Application
is	O
designed	O
specifically	O
to	O
represent	O
prescribed	O
targets	O
in	O
a	O
concise	O
and	O
flexible	O
way	O
to	O
direct	O
the	O
automation	O
of	O
text	B-Device
processing	I-Device
of	O
a	O
variety	O
of	O
input	O
data	O
,	O
in	O
a	O
form	O
easy	O
to	O
type	O
using	O
a	O
standard	O
ASCII	B-Protocol
keyboard	B-Device
.	O
</s>
<s>
A	O
very	O
simple	O
case	O
of	O
a	O
regular	B-Language
expression	I-Language
in	O
this	O
syntax	B-Application
is	O
to	O
locate	O
a	O
word	O
spelled	O
two	O
different	O
ways	O
in	O
a	O
text	B-Application
editor	I-Application
,	O
the	O
regular	B-Language
expression	I-Language
seriali[sz]e	O
matches	O
both	O
"	O
serialise	O
"	O
and	O
"	O
serialize	O
"	O
.	O
</s>
<s>
Wildcard	B-Algorithm
characters	I-Algorithm
also	O
achieve	O
this	O
,	O
but	O
are	O
more	O
limited	O
in	O
what	O
they	O
can	O
pattern	O
,	O
as	O
they	O
have	O
fewer	O
metacharacters	B-Algorithm
and	O
a	O
simple	O
language-base	O
.	O
</s>
<s>
The	O
usual	O
context	O
of	O
wildcard	B-Algorithm
characters	I-Algorithm
is	O
in	O
globbing	B-Language
similar	O
names	O
in	O
a	O
list	O
of	O
files	O
,	O
whereas	O
regexes	B-Language
are	O
usually	O
employed	O
in	O
applications	O
that	O
pattern-match	O
text	O
strings	O
in	O
general	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
regex	B-Language
matches	O
excess	O
whitespace	O
at	O
the	O
beginning	O
or	O
end	O
of	O
a	O
line	O
.	O
</s>
<s>
An	O
advanced	O
regular	B-Language
expression	I-Language
that	O
matches	O
any	O
numeral	O
is	O
.	O
</s>
<s>
A	O
regex	B-Language
processor	O
translates	O
a	O
regular	B-Language
expression	I-Language
in	O
the	O
above	O
syntax	B-Application
into	O
an	O
internal	O
representation	O
that	O
can	O
be	O
executed	O
and	O
matched	O
against	O
a	O
string	O
representing	O
the	O
text	O
being	O
searched	O
in	O
.	O
</s>
<s>
One	O
possible	O
approach	O
is	O
the	O
Thompson	B-General_Concept
's	I-General_Concept
construction	I-General_Concept
algorithm	I-General_Concept
to	O
construct	O
a	O
nondeterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
(	O
NFA	B-General_Concept
)	O
,	O
which	O
is	O
then	O
made	B-General_Concept
deterministic	I-General_Concept
and	O
the	O
resulting	O
deterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
(	O
DFA	B-General_Concept
)	O
is	O
run	O
on	O
the	O
target	O
text	O
string	O
to	O
recognize	O
substrings	O
that	O
match	O
the	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
The	O
picture	O
shows	O
the	O
NFA	B-General_Concept
scheme	O
N( s*	O
)	O
obtained	O
from	O
the	O
regular	B-Language
expression	I-Language
s*	O
,	O
where	O
s	O
denotes	O
a	O
simpler	O
regular	B-Language
expression	I-Language
in	O
turn	O
,	O
which	O
has	O
already	O
been	O
recursively	O
translated	O
to	O
the	O
NFA	B-General_Concept
N(s )	O
.	O
</s>
<s>
A	O
regular	B-Language
expression	I-Language
,	O
often	O
called	O
a	O
pattern	O
,	O
specifies	O
a	O
set	O
of	O
strings	O
required	O
for	O
a	O
particular	O
purpose	O
.	O
</s>
<s>
)	O
ndel	O
;	O
we	O
say	O
that	O
this	O
pattern	B-Language
matches	I-Language
each	O
of	O
the	O
three	O
strings	O
.	O
</s>
<s>
However	O
,	O
there	O
can	O
be	O
many	O
ways	O
to	O
write	O
a	O
regular	B-Language
expression	I-Language
for	O
the	O
same	O
set	O
of	O
strings	O
:	O
for	O
example	O
,	O
(	O
Hän|Han|Haen	O
)	O
del	O
also	O
specifies	O
the	O
same	O
set	O
of	O
three	O
strings	O
in	O
this	O
example	O
.	O
</s>
<s>
Most	O
formalisms	O
provide	O
the	O
following	O
operations	O
to	O
construct	O
regular	B-Language
expressions	I-Language
.	O
</s>
<s>
The	O
most	O
common	O
quantifiers	O
are	O
the	O
question	O
mark	O
?,	O
the	O
asterisk	B-Language
*	O
(	O
derived	O
from	O
the	O
Kleene	O
star	O
)	O
,	O
and	O
the	O
plus	O
sign	O
+	O
(	O
Kleene	O
plus	O
)	O
.	O
</s>
<s>
|The	O
asterisk	B-Language
indicates	O
zero	O
or	O
more	O
occurrences	O
of	O
the	O
preceding	O
element	O
.	O
</s>
<s>
For	O
example	O
,	O
ab*c	O
matches	O
"	O
ac	O
"	O
,	O
"	O
abc	O
"	O
,	O
"	O
abbc	O
"	O
,	O
"	O
abbbc	O
"	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
For	O
example	O
,	O
ab+c	O
matches	O
"	O
abc	O
"	O
,	O
"	O
abbc	O
"	O
,	O
"	O
abbbc	O
"	O
,	O
and	O
so	O
on	O
,	O
but	O
not	O
"	O
ac	O
"	O
.	O
</s>
<s>
The	O
wildcard	B-Algorithm
.	O
</s>
<s>
The	O
precise	O
syntax	B-Application
for	O
regular	B-Language
expressions	I-Language
varies	O
among	O
tools	O
and	O
with	O
context	O
;	O
more	O
detail	O
is	O
given	O
in	O
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
describe	O
regular	B-General_Concept
languages	I-General_Concept
in	O
formal	O
language	O
theory	O
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
consist	O
of	O
constants	O
,	O
which	O
denote	O
sets	O
of	O
strings	O
,	O
and	O
operator	O
symbols	O
,	O
which	O
denote	O
operations	O
over	O
these	O
sets	O
.	O
</s>
<s>
as	O
regular	B-Language
expressions	I-Language
:	O
</s>
<s>
(	O
literal	B-Language
character	I-Language
)	O
a	O
in	O
Σ	O
denoting	O
the	O
set	O
containing	O
only	O
the	O
character	O
a	O
.	O
</s>
<s>
to	O
produce	O
regular	B-Language
expressions	I-Language
:	O
</s>
<s>
For	O
example	O
,	O
let	O
R	O
denote	O
{	O
"	O
ab	O
"	O
,	O
"	O
c	B-Language
"	O
}	O
and	O
S	O
denote	O
{	O
"	O
d	O
"	O
,	O
"	O
ef	O
"	O
}	O
.	O
</s>
<s>
(	O
alternation	O
)	O
(	O
R|S	O
)	O
denotes	O
the	O
set	O
union	O
of	O
sets	O
described	O
by	O
R	O
and	O
S	O
.	O
For	O
example	O
,	O
if	O
R	O
describes	O
{	O
"	O
ab	O
"	O
,	O
"	O
c	B-Language
"	O
}	O
and	O
S	O
describes	O
{	O
"	O
ab	O
"	O
,	O
"	O
d	O
"	O
,	O
"	O
ef	O
"	O
}	O
,	O
expression	O
(	O
R|S	O
)	O
describes	O
{	O
"	O
ab	O
"	O
,	O
"	O
c	B-Language
"	O
,	O
"	O
d	O
"	O
,	O
"	O
ef	O
"	O
}	O
.	O
</s>
<s>
If	O
R	O
denotes	O
{	O
"	O
ab	O
"	O
,	O
"	O
c	B-Language
"	O
}	O
,	O
(	O
R*	O
)	O
denotes	O
{ε	O
,	O
"	O
ab	O
"	O
,	O
"	O
c	B-Language
"	O
,	O
"	O
abab	O
"	O
,	O
"	O
abc	O
"	O
,	O
"	O
cab	O
"	O
,	O
"	O
cc	O
"	O
,	O
"	O
ababab	O
"	O
,	O
"	O
abcab	O
"	O
,	O
...	O
}	O
.	O
</s>
<s>
For	O
example	O
,	O
(	O
ab	O
)	O
c	B-Language
can	O
be	O
written	O
as	O
abc	O
,	O
and	O
a|( b( c*	O
)	O
)	O
can	O
be	O
written	O
as	O
a|bc*	O
.	O
</s>
<s>
ab*( c|ε	O
)	O
denotes	O
the	O
set	O
of	O
strings	O
starting	O
with	O
"	O
a	O
"	O
,	O
then	O
zero	O
or	O
more	O
"	O
b	O
"	O
s	O
and	O
finally	O
optionally	O
a	O
"	O
c	B-Language
"	O
:	O
{	O
"	O
a	O
"	O
,	O
"	O
ac	O
"	O
,	O
"	O
ab	O
"	O
,	O
"	O
abc	O
"	O
,	O
"	O
abb	O
"	O
,	O
"	O
abbc	O
"	O
,	O
...	O
}	O
</s>
<s>
The	O
formal	O
definition	O
of	O
regular	B-Language
expressions	I-Language
is	O
minimal	O
on	O
purpose	O
,	O
and	O
avoids	O
defining	O
?	O
</s>
<s>
Sometimes	O
the	O
complement	O
operator	O
is	O
added	O
,	O
to	O
give	O
a	O
generalized	B-Language
regular	I-Language
expression	I-Language
;	O
here	O
Rc	O
matches	O
all	O
strings	O
over	O
Σ*	O
that	O
do	O
not	O
match	O
R	O
.	O
In	O
principle	O
,	O
the	O
complement	O
operator	O
is	O
redundant	O
,	O
because	O
it	O
does	O
n't	O
grant	O
any	O
more	O
expressive	O
power	O
.	O
</s>
<s>
However	O
,	O
it	O
can	O
make	O
a	O
regular	B-Language
expression	I-Language
much	O
more	O
concise	O
—	O
eliminating	O
a	O
single	O
complement	O
operator	O
can	O
cause	O
a	O
double	O
exponential	O
blow-up	O
of	O
its	O
length	O
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
in	O
this	O
sense	O
can	O
express	O
the	O
regular	B-General_Concept
languages	I-General_Concept
,	O
exactly	O
the	O
class	O
of	O
languages	O
accepted	O
by	O
deterministic	B-General_Concept
finite	I-General_Concept
automata	I-General_Concept
.	O
</s>
<s>
Some	O
classes	O
of	O
regular	B-General_Concept
languages	I-General_Concept
can	O
only	O
be	O
described	O
by	O
deterministic	B-General_Concept
finite	I-General_Concept
automata	I-General_Concept
whose	O
size	O
grows	O
exponentially	O
in	O
the	O
size	O
of	O
the	O
shortest	O
equivalent	O
regular	B-Language
expressions	I-Language
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
it	O
is	O
known	O
that	O
every	O
deterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
accepting	O
the	O
language	O
Lk	O
must	O
have	O
at	O
least	O
2k	O
states	O
.	O
</s>
<s>
Luckily	O
,	O
there	O
is	O
a	O
simple	O
mapping	O
from	O
regular	B-Language
expressions	I-Language
to	O
the	O
more	O
general	O
nondeterministic	B-General_Concept
finite	I-General_Concept
automata	I-General_Concept
(	O
NFAs	O
)	O
that	O
does	O
not	O
lead	O
to	O
such	O
a	O
blowup	O
in	O
size	O
;	O
for	O
this	O
reason	O
NFAs	O
are	O
often	O
used	O
as	O
alternative	O
representations	O
of	O
regular	B-General_Concept
languages	I-General_Concept
.	O
</s>
<s>
In	O
the	O
opposite	O
direction	O
,	O
there	O
are	O
many	O
languages	O
easily	O
described	O
by	O
a	O
DFA	B-General_Concept
that	O
are	O
not	O
easily	O
described	O
by	O
a	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
For	O
instance	O
,	O
determining	O
the	O
validity	O
of	O
a	O
given	O
ISBN	B-Library
requires	O
computing	O
the	O
modulus	O
of	O
the	O
integer	O
base	O
11	O
,	O
and	O
can	O
be	O
easily	O
implemented	O
with	O
an	O
11-state	O
DFA	B-General_Concept
.	O
</s>
<s>
However	O
,	O
a	O
regular	B-Language
expression	I-Language
to	O
answer	O
the	O
same	O
problem	O
of	O
divisibility	O
by	O
11	O
is	O
at	O
least	O
multiple	O
megabytes	O
in	O
length	O
.	O
</s>
<s>
Given	O
a	O
regular	B-Language
expression	I-Language
,	O
Thompson	B-General_Concept
's	I-General_Concept
construction	I-General_Concept
algorithm	I-General_Concept
computes	O
an	O
equivalent	O
nondeterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
.	O
</s>
<s>
A	O
conversion	O
in	O
the	O
opposite	O
direction	O
is	O
achieved	O
by	O
Kleene	B-General_Concept
's	I-General_Concept
algorithm	I-General_Concept
.	O
</s>
<s>
Finally	O
,	O
it	O
is	O
worth	O
noting	O
that	O
many	O
real-world	O
"	O
regular	B-Language
expression	I-Language
"	O
engines	O
implement	O
features	O
that	O
cannot	O
be	O
described	O
by	O
the	O
regular	B-Language
expressions	I-Language
in	O
the	O
sense	O
of	O
formal	O
language	O
theory	O
;	O
rather	O
,	O
they	O
implement	O
regexes	B-Language
.	O
</s>
<s>
As	O
seen	O
in	O
many	O
of	O
the	O
examples	O
above	O
,	O
there	O
is	O
more	O
than	O
one	O
way	O
to	O
construct	O
a	O
regular	B-Language
expression	I-Language
to	O
achieve	O
the	O
same	O
results	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
write	O
an	O
algorithm	O
that	O
,	O
for	O
two	O
given	O
regular	B-Language
expressions	I-Language
,	O
decides	O
whether	O
the	O
described	O
languages	O
are	O
equal	O
;	O
the	O
algorithm	O
reduces	O
each	O
expression	O
to	O
a	O
minimal	O
deterministic	B-General_Concept
finite	I-General_Concept
state	I-General_Concept
machine	I-General_Concept
,	O
and	O
determines	O
whether	O
they	O
are	O
isomorphic	O
(	O
equivalent	O
)	O
.	O
</s>
<s>
Algebraic	O
laws	O
for	O
regular	B-Language
expressions	I-Language
can	O
be	O
obtained	O
using	O
a	O
method	O
by	O
Gischer	O
which	O
is	O
best	O
explained	O
along	O
an	O
example	O
:	O
In	O
order	O
to	O
check	O
whether	O
(	O
X+Y	O
)	O
*	O
and	O
(	O
X*	O
Y*	O
)	O
*	O
denote	O
the	O
same	O
regular	B-General_Concept
language	I-General_Concept
,	O
for	O
all	O
regular	B-Language
expressions	I-Language
X	O
,	O
Y	O
,	O
it	O
is	O
necessary	O
and	O
sufficient	O
to	O
check	O
whether	O
the	O
particular	O
regular	B-Language
expressions	I-Language
(	O
a+b	O
)	O
*	O
and	O
(	O
a*	O
b*	O
)	O
*	O
denote	O
the	O
same	O
language	O
over	O
the	O
alphabet	O
Σ={a,b}	O
.	O
</s>
<s>
Every	O
regular	B-Language
expression	I-Language
can	O
be	O
written	O
solely	O
in	O
terms	O
of	O
the	O
Kleene	O
star	O
and	O
set	O
unions	O
over	O
finite	O
words	O
.	O
</s>
<s>
As	O
simple	O
as	O
the	O
regular	B-Language
expressions	I-Language
are	O
,	O
there	O
is	O
no	O
method	O
to	O
systematically	O
rewrite	O
them	O
to	O
some	O
normal	O
form	O
.	O
</s>
<s>
In	O
1991	O
,	O
Dexter	O
Kozen	O
axiomatized	O
regular	B-Language
expressions	I-Language
as	O
a	O
Kleene	O
algebra	O
,	O
using	O
equational	O
and	O
Horn	B-Application
clause	I-Application
axioms	O
.	O
</s>
<s>
Already	O
in	O
1964	O
,	O
Redko	O
had	O
proved	O
that	O
no	O
finite	O
set	O
of	O
purely	O
equational	O
axioms	O
can	O
characterize	O
the	O
algebra	O
of	O
regular	B-General_Concept
languages	I-General_Concept
.	O
</s>
<s>
A	O
regex	B-Language
pattern	B-Language
matches	I-Language
a	O
target	O
string	O
.	O
</s>
<s>
An	O
atom	O
is	O
a	O
single	O
point	O
within	O
the	O
regex	B-Language
pattern	O
which	O
it	O
tries	O
to	O
match	O
to	O
the	O
target	O
string	O
.	O
</s>
<s>
The	O
simplest	O
atom	O
is	O
a	O
literal	O
,	O
but	O
grouping	O
parts	O
of	O
the	O
pattern	O
to	O
match	O
an	O
atom	O
will	O
require	O
using	O
(	O
)	O
as	O
metacharacters	B-Algorithm
.	O
</s>
<s>
Metacharacters	B-Algorithm
help	O
form	O
:	O
atoms	O
;	O
quantifiers	O
telling	O
how	O
many	O
atoms	O
(	O
and	O
whether	O
it	O
is	O
a	O
greedy	B-Algorithm
quantifier	O
or	O
not	O
)	O
;	O
a	O
logical	O
OR	O
character	O
,	O
which	O
offers	O
a	O
set	O
of	O
alternatives	O
,	O
and	O
a	O
logical	O
NOT	O
character	O
,	O
which	O
negates	O
an	O
atom	O
's	O
existence	O
;	O
and	O
backreferences	O
to	O
refer	O
to	O
previous	O
atoms	O
of	O
a	O
completing	O
pattern	O
of	O
atoms	O
.	O
</s>
<s>
A	O
match	O
is	O
made	O
,	O
not	O
when	O
all	O
the	O
atoms	O
of	O
the	O
string	O
are	O
matched	O
,	O
but	O
rather	O
when	O
all	O
the	O
pattern	O
atoms	O
in	O
the	O
regex	B-Language
have	O
matched	O
.	O
</s>
<s>
The	O
idea	O
is	O
to	O
make	O
a	O
small	O
pattern	O
of	O
characters	O
stand	O
for	O
a	O
large	O
number	O
of	O
possible	O
strings	O
,	O
rather	O
than	O
compiling	B-Language
a	O
large	O
list	O
of	O
all	O
the	O
literal	O
possibilities	O
.	O
</s>
<s>
Depending	O
on	O
the	O
regex	B-Language
processor	O
there	O
are	O
about	O
fourteen	O
metacharacters	B-Algorithm
,	O
characters	O
that	O
may	O
or	O
may	O
not	O
have	O
their	O
literal	B-Language
character	I-Language
meaning	O
,	O
depending	O
on	O
context	O
,	O
or	O
whether	O
they	O
are	O
"	O
escaped	B-Algorithm
"	O
,	O
i.e.	O
</s>
<s>
Modern	O
and	O
POSIX	O
extended	O
regexes	B-Language
use	O
metacharacters	B-Algorithm
more	O
often	O
than	O
their	O
literal	O
meaning	O
,	O
so	O
to	O
avoid	O
"	O
backslash-osis	O
"	O
or	O
leaning	B-Language
toothpick	I-Language
syndrome	I-Language
it	O
makes	O
sense	O
to	O
have	O
a	O
metacharacter	B-Algorithm
escape	O
to	O
a	O
literal	O
mode	O
;	O
but	O
starting	O
out	O
,	O
it	O
makes	O
more	O
sense	O
to	O
have	O
the	O
four	O
bracketing	O
metacharacters	B-Algorithm
(	O
)	O
and	O
{	O
}	O
be	O
primarily	O
literal	O
,	O
and	O
"	O
escape	O
"	O
this	O
usual	O
meaning	O
to	O
become	O
metacharacters	B-Algorithm
.	O
</s>
<s>
The	O
usual	O
metacharacters	B-Algorithm
are	O
{}[]( 	O
)	O
^$	O
.	O
|*+	O
?	O
</s>
<s>
The	O
usual	O
characters	O
that	O
become	O
metacharacters	B-Algorithm
when	O
escaped	B-Algorithm
are	O
dswDSW	O
and	O
N	O
.	O
</s>
<s>
When	O
entering	O
a	O
regex	B-Language
in	O
a	O
programming	O
language	O
,	O
they	O
may	O
be	O
represented	O
as	O
a	O
usual	O
string	B-Language
literal	I-Language
,	O
hence	O
usually	O
quoted	O
;	O
this	O
is	O
common	O
in	O
C	B-Language
,	O
Java	B-Language
,	O
and	O
Python	B-Language
for	O
instance	O
,	O
where	O
the	O
regex	B-Language
re	O
is	O
entered	O
as	O
"	O
re	O
"	O
.	O
</s>
<s>
However	O
,	O
they	O
are	O
often	O
written	O
with	O
slashes	O
as	O
delimiters	B-Algorithm
,	O
as	O
in	O
/re/	O
for	O
the	O
regex	B-Language
re	O
.	O
</s>
<s>
This	O
originates	O
in	O
ed	B-Application
,	O
where	O
/	O
is	O
the	O
editor	O
command	O
for	O
searching	O
,	O
and	O
an	O
expression	O
/re/	O
can	O
be	O
used	O
to	O
specify	O
a	O
range	O
of	O
lines	O
(	O
matching	O
the	O
pattern	O
)	O
,	O
which	O
can	O
be	O
combined	O
with	O
other	O
commands	O
on	O
either	O
side	O
,	O
most	O
famously	O
g/re/p	B-Application
as	O
in	O
grep	B-Application
(	O
"	O
global	O
regex	B-Language
print	O
"	O
)	O
,	O
which	O
is	O
included	O
in	O
most	O
Unix-based	O
operating	O
systems	O
,	O
such	O
as	O
Linux	B-Application
distributions	O
.	O
</s>
<s>
A	O
similar	O
convention	O
is	O
used	O
in	O
sed	B-Application
,	O
where	O
search	O
and	O
replace	O
is	O
given	O
by	O
s/re/replacement/	O
and	O
patterns	O
can	O
be	O
joined	O
with	O
a	O
comma	O
to	O
specify	O
a	O
range	O
of	O
lines	O
as	O
in	O
/re1/	O
,	O
/re2/	O
.	O
</s>
<s>
This	O
notation	O
is	O
particularly	O
well	O
known	O
due	O
to	O
its	O
use	O
in	O
Perl	B-Language
,	O
where	O
it	O
forms	O
part	O
of	O
the	O
syntax	B-Application
distinct	O
from	O
normal	O
string	B-Language
literals	I-Language
.	O
</s>
<s>
In	O
some	O
cases	O
,	O
such	O
as	O
sed	B-Application
and	O
Perl	B-Language
,	O
alternative	O
delimiters	B-Algorithm
can	O
be	O
used	O
to	O
avoid	O
collision	O
with	O
contents	O
,	O
and	O
to	O
avoid	O
having	O
to	O
escape	O
occurrences	O
of	O
the	O
delimiter	B-Algorithm
character	O
in	O
the	O
contents	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
sed	B-Application
the	O
command	O
s	O
,	O
/	O
,	O
X	O
,	O
will	O
replace	O
a	O
/	O
with	O
an	O
X	O
,	O
using	O
commas	O
as	O
delimiters	B-Algorithm
.	O
</s>
<s>
The	O
IEEE	O
POSIX	O
standard	O
has	O
three	O
sets	O
of	O
compliance	O
:	O
BRE	O
(	O
Basic	O
Regular	B-Language
Expressions	I-Language
)	O
,	O
ERE	O
(	O
Extended	O
Regular	B-Language
Expressions	I-Language
)	O
,	O
and	O
SRE	O
(	O
Simple	O
Regular	B-Language
Expressions	I-Language
)	O
.	O
</s>
<s>
SRE	O
is	O
deprecated	B-General_Concept
,	O
in	O
favor	O
of	O
BRE	O
,	O
as	O
both	O
provide	O
backward	B-General_Concept
compatibility	I-General_Concept
.	O
</s>
<s>
ERE	O
adds	O
?,	O
+	O
,	O
and	O
|	O
,	O
and	O
it	O
removes	O
the	O
need	O
to	O
escape	O
the	O
metacharacters	B-Algorithm
(	O
)	O
and	O
{	O
}	O
,	O
which	O
are	O
required	O
in	O
BRE	O
.	O
</s>
<s>
Furthermore	O
,	O
as	O
long	O
as	O
the	O
POSIX	O
standard	O
syntax	B-Application
for	O
regexes	B-Language
is	O
adhered	O
to	O
,	O
there	O
can	O
be	O
,	O
and	O
often	O
is	O
,	O
additional	O
syntax	B-Application
to	O
serve	O
specific	O
(	O
yet	O
POSIX	O
compliant	O
)	O
applications	O
.	O
</s>
<s>
Although	O
POSIX.2	O
leaves	O
some	O
implementation	O
specifics	O
undefined	O
,	O
BRE	O
and	O
ERE	O
provide	O
a	O
"	O
standard	O
"	O
which	O
has	O
since	O
been	O
adopted	O
as	O
the	O
default	O
syntax	B-Application
of	O
many	O
tools	O
,	O
where	O
the	O
choice	O
of	O
BRE	O
or	O
ERE	O
modes	O
is	O
usually	O
a	O
supported	O
option	O
.	O
</s>
<s>
For	O
example	O
,	O
GNU	B-Operating_System
grep	B-Application
has	O
the	O
following	O
options	O
:	O
"	O
grep	B-Application
-E	O
"	O
for	O
ERE	O
,	O
and	O
"	O
grep	B-Application
-G	O
"	O
for	O
BRE	O
(	O
the	O
default	O
)	O
,	O
and	O
"	O
grep	B-Application
-P	O
"	O
for	O
Perl	B-Language
regexes	B-Language
.	O
</s>
<s>
Perl	B-Language
regexes	B-Language
have	O
become	O
a	O
de	O
facto	O
standard	O
,	O
having	O
a	O
rich	O
and	O
powerful	O
set	O
of	O
atomic	O
expressions	O
.	O
</s>
<s>
Perl	B-Language
has	O
no	O
"	O
basic	O
"	O
or	O
"	O
extended	O
"	O
levels	O
.	O
</s>
<s>
As	O
in	O
POSIX	O
EREs	O
,	O
(	O
)	O
and	O
{	O
}	O
are	O
treated	O
as	O
metacharacters	B-Algorithm
unless	O
escaped	B-Algorithm
;	O
other	O
metacharacters	B-Algorithm
are	O
known	O
to	O
be	O
literal	O
or	O
symbolic	O
based	O
on	O
context	O
alone	O
.	O
</s>
<s>
In	O
the	O
POSIX	O
standard	O
,	O
Basic	O
Regular	O
Syntax	B-Application
(	O
BRE	O
)	O
requires	O
that	O
the	O
metacharacters	B-Algorithm
(	O
)	O
and	O
{	O
}	O
be	O
designated	O
\( \	O
)	O
and	O
\{\},	O
whereas	O
Extended	O
Regular	O
Syntax	B-Application
(	O
ERE	O
)	O
does	O
not	O
.	O
</s>
<s>
Metacharacter	B-Algorithm
Description^Matches	O
the	O
starting	O
position	O
within	O
the	O
string	O
.	O
</s>
<s>
For	O
example	O
,	O
a.c	O
matches	O
"	O
abc	O
"	O
,	O
etc.	O
,	O
but	O
 [ a.c ] 	O
matches	O
only	O
"	O
a	O
"	O
,	O
"	O
.	O
</s>
<s>
"	O
,	O
or	O
"	O
c	B-Language
"	O
.	O
</s>
<s>
For	O
example	O
,	O
 [ abc ] 	O
matches	O
"	O
a	O
"	O
,	O
"	O
b	O
"	O
,	O
or	O
"	O
c	B-Language
"	O
.	O
</s>
<s>
These	O
forms	O
can	O
be	O
mixed	O
:	O
 [ abcx-z ] 	O
matches	O
"	O
a	O
"	O
,	O
"	O
b	O
"	O
,	O
"	O
c	B-Language
"	O
,	O
"	O
x	O
"	O
,	O
"	O
y	O
"	O
,	O
or	O
"	O
z	O
"	O
,	O
as	O
does	O
 [ a-cx-z ] 	O
.	O
</s>
<s>
The	O
-	O
character	O
is	O
treated	O
as	O
a	O
literal	B-Language
character	I-Language
if	O
it	O
is	O
the	O
last	O
or	O
the	O
first	O
(	O
after	O
the	O
^	O
,	O
if	O
present	O
)	O
character	O
within	O
the	O
brackets	O
:	O
[abc-],	O
 [ -abc ] 	O
.	O
</s>
<s>
For	O
example	O
,	O
 [ ^abc ] 	O
matches	O
any	O
character	O
other	O
than	O
"	O
a	O
"	O
,	O
"	O
b	O
"	O
,	O
or	O
"	O
c	B-Language
"	O
.	O
</s>
<s>
For	O
example	O
,	O
ab*c	O
matches	O
"	O
ac	O
"	O
,	O
"	O
abc	O
"	O
,	O
"	O
abbbc	O
"	O
,	O
etc	O
.	O
</s>
<s>
This	O
is	O
not	O
found	O
in	O
a	O
few	O
older	O
instances	O
of	O
regexes	B-Language
.	O
</s>
<s>
</s>
<s>
The	O
meaning	O
of	O
metacharacters	B-Algorithm
escaped	B-Algorithm
with	O
a	O
backslash	O
is	O
reversed	O
for	O
some	O
characters	O
in	O
the	O
POSIX	O
Extended	O
Regular	B-Language
Expression	I-Language
(	O
ERE	O
)	O
syntax	B-Application
.	O
</s>
<s>
With	O
this	O
syntax	B-Application
,	O
a	O
backslash	O
causes	O
the	O
metacharacter	B-Algorithm
to	O
be	O
treated	O
as	O
a	O
literal	B-Language
character	I-Language
.	O
</s>
<s>
Additionally	O
,	O
support	O
is	O
removed	O
for	O
\n	O
backreferences	O
and	O
the	O
following	O
metacharacters	B-Algorithm
are	O
added	O
:	O
</s>
<s>
Metacharacter	B-Algorithm
Description	O
?	O
</s>
<s>
For	O
example	O
,	O
ab	O
?	O
c	B-Language
matches	O
only	O
"	O
ac	O
"	O
or	O
"	O
abc	O
"	O
.	O
</s>
<s>
For	O
example	O
,	O
ab+c	O
matches	O
"	O
abc	O
"	O
,	O
"	O
abbc	O
"	O
,	O
"	O
abbbc	O
"	O
,	O
and	O
so	O
on	O
,	O
but	O
not	O
"	O
ac	O
"	O
.	O
</s>
<s>
POSIX	O
Extended	O
Regular	B-Language
Expressions	I-Language
can	O
often	O
be	O
used	O
with	O
modern	O
Unix	B-Application
utilities	O
by	O
including	O
the	O
command	B-Application
line	I-Application
flag	O
-E	O
.	O
</s>
<s>
The	O
character	O
class	O
is	O
the	O
most	O
basic	O
regex	B-Language
concept	O
after	O
a	O
literal	O
match	O
.	O
</s>
<s>
lowercase	O
a	O
to	O
uppercase	O
Z	O
)	O
,	O
the	O
computer	O
's	O
locale	O
settings	O
determine	O
the	O
contents	O
by	O
the	O
numeric	O
ordering	O
of	O
the	O
character	B-General_Concept
encoding	I-General_Concept
.	O
</s>
<s>
So	O
the	O
POSIX	O
standard	O
defines	O
a	O
character	O
class	O
,	O
which	O
will	O
be	O
known	O
by	O
the	O
regex	B-Language
processor	O
installed	O
.	O
</s>
<s>
Description	O
POSIX	O
Perl/Tcl	O
Vim	B-Application
Java	B-Language
ASCII	B-Protocol
ASCII	B-Protocol
characters	I-Protocol
\p{ASCII}	O
 [ \x00-\x7F ] 	O
Alphanumeric	O
characters	O
 [ :alnum: ] 	O
\p{Alnum}	O
 [ A-Za-z0-9 ] 	O
Alphanumeric	O
characters	O
plus	O
"	O
_	O
"	O
\w	O
\w	O
\w	O
 [ A-Za-z0-9_ ] 	O
Non-word	O
characters	O
\W	O
\W	O
\W	O
 [ ^A-Za-z0-9_ ] 	O
Alphabetic	O
characters	O
 [ :alpha: ] 	O
\a	O
\p{Alpha}	O
 [ A-Za-z ] 	O
Space	O
and	O
tab	O
 [ :blank: ] 	O
\s	O
\p{Blank}	O
[	O
\t ]	O
Word	O
boundaries	O
\b	O
\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
?	O
</s>
<s>
The	O
editor	O
Vim	B-Application
further	O
distinguishes	O
word	O
and	O
word-head	O
classes	O
(	O
using	O
the	O
notation	O
and	O
)	O
since	O
in	O
many	O
programming	O
languages	O
the	O
characters	O
that	O
can	O
begin	O
an	O
identifier	O
are	O
not	O
the	O
same	O
as	O
those	O
that	O
can	O
occur	O
in	O
other	O
positions	O
:	O
numbers	O
are	O
generally	O
excluded	O
,	O
so	O
an	O
identifier	O
would	O
look	O
like	O
or	O
in	O
POSIX	O
notation	O
.	O
</s>
<s>
Note	O
that	O
what	O
the	O
POSIX	O
regex	B-Language
standards	O
call	O
character	O
classes	O
are	O
commonly	O
referred	O
to	O
as	O
POSIX	O
character	O
classes	O
in	O
other	O
regex	B-Language
flavors	O
which	O
support	O
them	O
.	O
</s>
<s>
With	O
most	O
other	O
regex	B-Language
flavors	O
,	O
the	O
term	O
character	O
class	O
is	O
used	O
to	O
describe	O
what	O
POSIX	O
calls	O
bracket	O
expressions	O
.	O
</s>
<s>
Because	O
of	O
its	O
expressive	O
power	O
and	O
(	O
relative	O
)	O
ease	O
of	O
reading	O
,	O
many	O
other	O
utilities	O
and	O
programming	O
languages	O
have	O
adopted	O
syntax	B-Application
similar	O
to	O
Perl's—for	O
example	O
,	O
Java	B-Language
,	O
JavaScript	B-Language
,	O
Julia	B-Application
,	O
Python	B-Language
,	O
Ruby	B-Language
,	O
Qt	B-Language
,	O
Microsoft	B-Application
's	I-Application
.NET	I-Application
Framework	I-Application
,	O
and	O
XML	O
Schema	O
.	O
</s>
<s>
Some	O
languages	O
and	O
tools	O
such	O
as	O
Boost	B-Language
and	O
PHP	B-Application
support	O
multiple	O
regex	B-Language
flavors	O
.	O
</s>
<s>
Perl-derivative	O
regex	B-Language
implementations	O
are	O
not	O
identical	O
and	O
usually	O
implement	O
a	O
subset	O
of	O
features	O
found	O
in	O
Perl	B-Language
5.0	O
,	O
released	O
in	O
1994	O
.	O
</s>
<s>
Perl	B-Language
sometimes	O
does	O
incorporate	O
features	O
initially	O
found	O
in	O
other	O
languages	O
.	O
</s>
<s>
For	O
example	O
,	O
Perl	B-Language
5.10	O
implements	O
syntactic	O
extensions	O
originally	O
developed	O
in	O
PCRE	B-Language
and	O
Python	B-Language
.	O
</s>
<s>
In	O
Python	B-Language
and	O
some	O
other	O
implementations	O
(	O
e.g.	O
</s>
<s>
Java	B-Language
)	O
,	O
the	O
three	O
common	O
quantifiers	O
( *	O
,	O
+	O
and	O
?	O
)	O
</s>
<s>
are	O
greedy	B-Algorithm
by	O
default	O
because	O
they	O
match	O
as	O
many	O
characters	O
as	O
possible	O
.	O
</s>
<s>
In	O
Java	B-Language
and	O
Python	B-Language
3.11	O
+	O
,	O
quantifiers	O
may	O
be	O
made	O
possessive	O
by	O
appending	O
a	O
plus	O
sign	O
,	O
which	O
disables	O
backing	O
off	O
(	O
in	O
a	O
backtracking	B-Algorithm
engine	O
)	O
,	O
even	O
if	O
doing	O
so	O
would	O
allow	O
the	O
overall	O
match	O
to	O
succeed	O
:	O
While	O
the	O
regex	B-Language
"	O
.	O
</s>
<s>
matches	O
the	O
entire	O
line	O
,	O
the	O
regex	B-Language
"	O
.	O
</s>
<s>
Another	O
common	O
extension	O
serving	O
the	O
same	O
function	O
is	O
atomic	O
grouping	O
,	O
which	O
disables	O
backtracking	B-Algorithm
for	O
a	O
parenthesized	O
group	O
.	O
</s>
<s>
The	O
typical	O
syntax	B-Application
is	O
.	O
</s>
<s>
For	O
example	O
,	O
while	O
matches	O
both	O
and	O
,	O
only	O
matches	O
because	O
the	O
engine	O
is	O
forbidden	O
from	O
backtracking	B-Algorithm
and	O
so	O
cannot	O
try	O
setting	O
the	O
group	O
to	O
"	O
w	O
"	O
after	O
matching	O
"	O
wi	O
"	O
.	O
</s>
<s>
Possessive	O
quantifiers	O
are	O
easier	O
to	O
implement	O
than	O
greedy	B-Algorithm
and	O
lazy	O
quantifiers	O
,	O
and	O
are	O
typically	O
more	O
efficient	O
at	O
runtime	O
.	O
</s>
<s>
Many	O
features	O
found	O
in	O
virtually	O
all	O
modern	O
regular	B-Language
expression	I-Language
libraries	B-Library
provide	O
an	O
expressive	O
power	O
that	O
exceeds	O
the	O
regular	B-General_Concept
languages	I-General_Concept
.	O
</s>
<s>
However	O
,	O
pattern	B-Language
matching	I-Language
with	O
an	O
unbounded	O
number	O
of	O
backreferences	O
,	O
as	O
supported	O
by	O
numerous	O
modern	O
tools	O
,	O
is	O
still	O
context	O
sensitive	O
.	O
</s>
<s>
However	O
,	O
many	O
tools	O
,	O
libraries	B-Library
,	O
and	O
engines	O
that	O
provide	O
such	O
constructions	O
still	O
use	O
the	O
term	O
regular	B-Language
expression	I-Language
for	O
their	O
patterns	O
.	O
</s>
<s>
This	O
has	O
led	O
to	O
a	O
nomenclature	O
where	O
the	O
term	O
regular	B-Language
expression	I-Language
has	O
different	O
meanings	O
in	O
formal	O
language	O
theory	O
and	O
pattern	B-Language
matching	I-Language
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
some	O
people	O
have	O
taken	O
to	O
using	O
the	O
term	O
regex	B-Language
,	O
regexp	B-Language
,	O
or	O
simply	O
pattern	O
to	O
describe	O
the	O
latter	O
.	O
</s>
<s>
Larry	O
Wall	O
,	O
author	O
of	O
the	O
Perl	B-Language
programming	I-Language
language	I-Language
,	O
writes	O
in	O
an	O
essay	O
about	O
the	O
design	O
of	O
Raku	B-Application
:	O
</s>
<s>
Other	O
features	O
not	O
found	O
in	O
describing	O
regular	B-General_Concept
languages	I-General_Concept
include	O
assertions	O
.	O
</s>
<s>
Lookarounds	O
define	O
the	O
surrounding	O
of	O
a	O
match	O
and	O
do	O
n't	O
spill	O
into	O
the	O
match	O
itself	O
,	O
a	O
feature	O
only	O
relevant	O
for	O
the	O
use	O
case	O
of	O
string	B-Algorithm
searching	I-Algorithm
.	O
</s>
<s>
Some	O
of	O
them	O
can	O
be	O
simulated	O
in	O
a	O
regular	B-General_Concept
language	I-General_Concept
by	O
treating	O
the	O
surroundings	O
as	O
a	O
part	O
of	O
the	O
language	O
as	O
well	O
.	O
</s>
<s>
The	O
look-ahead	O
assertions	O
and	O
have	O
been	O
attested	O
since	O
at	O
least	O
1994	O
,	O
starting	O
with	O
Perl	B-Language
5	O
.	O
</s>
<s>
The	O
look-behind	O
assertions	O
and	O
are	O
attested	O
since	O
1997	O
in	O
a	O
commit	O
by	O
Ilya	O
Zakharevich	O
to	O
Perl	B-Language
5.005	O
.	O
</s>
<s>
There	O
are	O
at	O
least	O
three	O
different	O
algorithms	O
that	O
decide	O
whether	O
and	O
how	O
a	O
given	O
regex	B-Language
matches	O
a	O
string	O
.	O
</s>
<s>
The	O
oldest	O
and	O
fastest	O
relies	O
on	O
a	O
result	O
in	O
formal	O
language	O
theory	O
that	O
allows	O
every	O
nondeterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
(	O
NFA	B-General_Concept
)	O
to	O
be	O
transformed	O
into	O
a	O
deterministic	B-General_Concept
finite	I-General_Concept
automaton	I-General_Concept
(	O
DFA	B-General_Concept
)	O
.	O
</s>
<s>
The	O
DFA	B-General_Concept
can	O
be	O
constructed	O
explicitly	O
and	O
then	O
run	O
on	O
the	O
resulting	O
input	O
string	O
one	O
symbol	O
at	O
a	O
time	O
.	O
</s>
<s>
Constructing	O
the	O
DFA	B-General_Concept
for	O
a	O
regular	B-Language
expression	I-Language
of	O
size	O
m	O
has	O
the	O
time	O
and	O
memory	O
cost	O
of	O
O(2m )	O
,	O
but	O
it	O
can	O
be	O
run	O
on	O
a	O
string	O
of	O
size	O
n	O
in	O
time	O
O(n )	O
.	O
</s>
<s>
An	O
alternative	O
approach	O
is	O
to	O
simulate	O
the	O
NFA	B-General_Concept
directly	O
,	O
essentially	O
building	O
each	O
DFA	B-General_Concept
state	O
on	O
demand	O
and	O
then	O
discarding	O
it	O
at	O
the	O
next	O
step	O
.	O
</s>
<s>
This	O
keeps	O
the	O
DFA	B-General_Concept
implicit	O
and	O
avoids	O
the	O
exponential	O
construction	O
cost	O
,	O
but	O
running	O
cost	O
rises	O
to	O
O(mn )	O
.	O
</s>
<s>
The	O
explicit	O
approach	O
is	O
called	O
the	O
DFA	B-General_Concept
algorithm	O
and	O
the	O
implicit	O
approach	O
the	O
NFA	B-General_Concept
algorithm	O
.	O
</s>
<s>
Adding	O
caching	O
to	O
the	O
NFA	B-General_Concept
algorithm	O
is	O
often	O
called	O
the	O
"	O
lazy	O
DFA	B-General_Concept
"	O
algorithm	O
,	O
or	O
just	O
the	O
DFA	B-General_Concept
algorithm	O
without	O
making	O
a	O
distinction	O
.	O
</s>
<s>
The	O
third	O
algorithm	O
is	O
to	O
match	O
the	O
pattern	O
against	O
the	O
input	O
string	O
by	O
backtracking	B-Algorithm
.	O
</s>
<s>
This	O
algorithm	O
is	O
commonly	O
called	O
NFA	B-General_Concept
,	O
but	O
this	O
terminology	O
can	O
be	O
confusing	O
.	O
</s>
<s>
This	O
behavior	O
can	O
cause	O
a	O
security	O
problem	O
called	O
Regular	B-Algorithm
expression	I-Algorithm
Denial	I-Algorithm
of	I-Algorithm
Service	I-Algorithm
(	O
ReDoS	B-Algorithm
)	O
.	O
</s>
<s>
Although	O
backtracking	B-Algorithm
implementations	O
only	O
give	O
an	O
exponential	O
guarantee	O
in	O
the	O
worst	O
case	O
,	O
they	O
provide	O
much	O
greater	O
flexibility	O
and	O
expressive	O
power	O
.	O
</s>
<s>
For	O
example	O
,	O
any	O
implementation	O
which	O
allows	O
the	O
use	O
of	O
backreferences	O
,	O
or	O
implements	O
the	O
various	O
extensions	O
introduced	O
by	O
Perl	B-Language
,	O
must	O
include	O
some	O
kind	O
of	O
backtracking	B-Algorithm
.	O
</s>
<s>
Some	O
implementations	O
try	O
to	O
provide	O
the	O
best	O
of	O
both	O
algorithms	O
by	O
first	O
running	O
a	O
fast	O
DFA	B-General_Concept
algorithm	O
,	O
and	O
revert	O
to	O
a	O
potentially	O
slower	O
backtracking	B-Algorithm
algorithm	I-Algorithm
only	O
when	O
a	O
backreference	O
is	O
encountered	O
during	O
the	O
match	O
.	O
</s>
<s>
GNU	B-Operating_System
grep	B-Application
(	O
and	O
the	O
underlying	O
gnulib	O
DFA	B-General_Concept
)	O
uses	O
such	O
a	O
strategy	O
.	O
</s>
<s>
Sublinear	O
runtime	O
algorithms	O
have	O
been	O
achieved	O
using	O
Boyer-Moore	O
(	O
BM	O
)	O
based	O
algorithms	O
and	O
related	O
DFA	B-General_Concept
optimization	O
techniques	O
such	O
as	O
the	O
reverse	O
scan	O
.	O
</s>
<s>
GNU	B-Operating_System
grep	B-Application
,	O
which	O
supports	O
a	O
wide	O
variety	O
of	O
POSIX	O
syntaxes	B-Application
and	O
extensions	O
,	O
uses	O
BM	O
for	O
a	O
first-pass	O
prefiltering	O
,	O
and	O
then	O
uses	O
an	O
implicit	O
DFA	B-General_Concept
.	O
</s>
<s>
Wu	O
agrep	B-Device
,	O
which	O
implements	O
approximate	O
matching	O
,	O
combines	O
the	O
prefiltering	O
into	O
the	O
DFA	B-General_Concept
in	O
BDM	O
(	O
backward	O
DAWG	O
matching	O
)	O
.	O
</s>
<s>
NR-grep	O
'	O
s	O
BNDM	O
extends	O
the	O
BDM	O
technique	O
with	O
Shift-Or	O
bit-level	O
parallelism	O
.	O
</s>
<s>
A	O
few	O
theoretical	O
alternatives	O
to	O
backtracking	B-Algorithm
for	O
backreferences	O
exist	O
,	O
and	O
their	O
"	O
exponents	O
"	O
are	O
tamer	O
in	O
that	O
they	O
are	O
only	O
related	O
to	O
the	O
number	O
of	O
backreferences	O
,	O
a	O
fixed	O
property	O
of	O
some	O
regexp	B-Language
languages	O
such	O
as	O
POSIX	O
.	O
</s>
<s>
One	O
naive	O
method	O
that	O
duplicates	O
a	O
non-backtracking	O
NFA	B-General_Concept
for	O
each	O
backreference	O
note	O
has	O
a	O
complexity	O
of	O
time	O
and	O
space	O
for	O
a	O
haystack	O
of	O
length	O
n	O
and	O
k	O
backreferences	O
in	O
the	O
RegExp	B-Language
.	O
</s>
<s>
A	O
very	O
recent	O
theoretical	O
work	O
based	O
on	O
memory	O
automata	O
gives	O
a	O
tighter	O
bound	O
based	O
on	O
"	O
active	O
"	O
variable	O
nodes	O
used	O
,	O
and	O
a	O
polynomial	O
possibility	O
for	O
some	O
backreferenced	O
regexps	B-Language
.	O
</s>
<s>
In	O
theoretical	O
terms	O
,	O
any	O
token	O
set	O
can	O
be	O
matched	O
by	O
regular	B-Language
expressions	I-Language
as	O
long	O
as	O
it	O
is	O
pre-defined	O
.	O
</s>
<s>
In	O
terms	O
of	O
historical	O
implementations	O
,	O
regexes	B-Language
were	O
originally	O
written	O
to	O
use	O
ASCII	B-Protocol
characters	I-Protocol
as	O
their	O
token	O
set	O
though	O
regex	B-Language
libraries	B-Library
have	O
supported	O
numerous	O
other	O
character	B-General_Concept
sets	I-General_Concept
.	O
</s>
<s>
Many	O
modern	O
regex	B-Language
engines	O
offer	O
at	O
least	O
some	O
support	O
for	O
Unicode	O
.	O
</s>
<s>
In	O
most	O
respects	O
it	O
makes	O
no	O
difference	O
what	O
the	O
character	B-General_Concept
set	I-General_Concept
is	O
,	O
but	O
some	O
issues	O
do	O
arise	O
when	O
extending	O
regexes	B-Language
to	O
support	O
Unicode	O
.	O
</s>
<s>
Some	O
regex	B-Language
libraries	B-Library
expect	O
to	O
work	O
on	O
some	O
particular	O
encoding	O
instead	O
of	O
on	O
abstract	O
Unicode	O
characters	O
.	O
</s>
<s>
In	O
contrast	O
,	O
Perl	B-Language
and	O
Java	B-Language
are	O
agnostic	O
on	O
encodings	O
,	O
instead	O
operating	O
on	O
decoded	O
characters	O
internally	O
.	O
</s>
<s>
Many	O
regex	B-Language
engines	O
support	O
only	O
the	O
Basic	O
Multilingual	O
Plane	O
,	O
that	O
is	O
,	O
the	O
characters	O
which	O
can	O
be	O
encoded	O
with	O
only	O
16	O
bits	O
.	O
</s>
<s>
Currently	O
(	O
as	O
of	O
)	O
only	O
a	O
few	O
regex	B-Language
engines	O
(	O
e.g.	O
,	O
Perl	B-Language
's	O
and	O
Java	B-Language
's	O
)	O
can	O
handle	O
the	O
full	O
21-bit	O
Unicode	O
range	O
.	O
</s>
<s>
Extending	O
ASCII-oriented	O
constructs	O
to	O
Unicode	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
ASCII-based	O
implementations	O
,	O
character	O
ranges	O
of	O
the	O
form	O
 [ x-y ] 	O
are	O
valid	O
wherever	O
x	O
and	O
y	O
have	O
code	O
points	O
in	O
the	O
range	O
 [ 0x00 , 0x7F ] 	O
and	O
codepoint(x )	O
≤	O
codepoint(y )	O
.	O
</s>
<s>
Other	O
engines	O
,	O
such	O
as	O
that	O
of	O
the	O
Vim	B-Application
editor	I-Application
,	O
allow	O
block-crossing	O
but	O
the	O
character	O
values	O
must	O
not	O
be	O
more	O
than	O
256	O
apart	O
.	O
</s>
<s>
Some	O
case-insensitivity	O
flags	O
affect	O
only	O
the	O
ASCII	B-Protocol
characters	I-Protocol
.	O
</s>
<s>
Some	O
engines	O
have	O
two	O
different	O
flags	O
,	O
one	O
for	O
ASCII	B-Protocol
,	O
the	O
other	O
for	O
Unicode	O
.	O
</s>
<s>
As	O
ASCII	B-Protocol
has	O
case	O
distinction	O
,	O
case	O
insensitivity	O
became	O
a	O
logical	O
feature	O
in	O
text	B-Algorithm
searching	I-Algorithm
.	O
</s>
<s>
In	O
Perl	B-Language
and	O
the	O
library	B-Library
,	O
properties	O
of	O
the	O
form	O
\p{InX}	O
or	O
\p{Block=X}	O
match	O
characters	O
in	O
block	O
X	O
and	O
\P{InX}	O
or	O
\P{Block=X}	O
matches	O
code	O
points	O
not	O
in	O
that	O
block	O
.	O
</s>
<s>
Most	O
general-purpose	B-Language
programming	I-Language
languages	I-Language
support	O
regex	B-Language
capabilities	O
,	O
either	O
natively	O
or	O
via	O
libraries	B-Library
.	O
</s>
<s>
Regexes	B-Language
are	O
useful	O
in	O
a	O
wide	O
variety	O
of	O
text	B-Device
processing	I-Device
tasks	O
,	O
and	O
more	O
generally	O
string	B-Language
processing	I-Language
,	O
where	O
the	O
data	O
need	O
not	O
be	O
textual	O
.	O
</s>
<s>
Common	O
applications	O
include	O
data	O
validation	O
,	O
data	B-General_Concept
scraping	I-General_Concept
(	O
especially	O
web	B-Application
scraping	I-Application
)	O
,	O
data	B-General_Concept
wrangling	I-General_Concept
,	O
simple	O
parsing	B-Language
,	O
the	O
production	O
of	O
syntax	B-Application
highlighting	O
systems	O
,	O
and	O
many	O
other	O
tasks	O
.	O
</s>
<s>
While	O
regexes	B-Language
would	O
be	O
useful	O
on	O
Internet	B-Application
search	I-Application
engines	I-Application
,	O
processing	O
them	O
across	O
the	O
entire	O
database	O
could	O
consume	O
excessive	O
computer	O
resources	O
depending	O
on	O
the	O
complexity	O
and	O
design	O
of	O
the	O
regex	B-Language
.	O
</s>
<s>
Although	O
in	O
many	O
cases	O
system	O
administrators	O
can	O
run	O
regex-based	O
queries	O
internally	O
,	O
most	O
search	B-Application
engines	I-Application
do	O
not	O
offer	O
regex	B-Language
support	O
to	O
the	O
public	O
.	O
</s>
<s>
Notable	O
exceptions	O
include	O
Google	B-Application
Code	I-Application
Search	I-Application
and	O
Exalead	B-Application
.	O
</s>
<s>
However	O
,	O
Google	B-Application
Code	I-Application
Search	I-Application
was	O
shut	O
down	O
in	O
January	O
2012	O
.	O
</s>
<s>
The	O
specific	O
syntax	B-Application
rules	O
vary	O
depending	O
on	O
the	O
specific	O
implementation	O
,	O
programming	O
language	O
,	O
or	O
library	B-Library
in	O
use	O
.	O
</s>
<s>
Additionally	O
,	O
the	O
functionality	O
of	O
regex	B-Language
implementations	O
can	O
vary	O
between	O
versions	O
.	O
</s>
<s>
Because	O
regexes	B-Language
can	O
be	O
difficult	O
to	O
both	O
explain	O
and	O
understand	O
without	O
examples	O
,	O
interactive	O
websites	O
for	O
testing	O
regexes	B-Language
are	O
a	O
useful	O
resource	O
for	O
learning	O
regexes	B-Language
by	O
experimentation	O
.	O
</s>
<s>
This	O
section	O
provides	O
a	O
basic	O
description	O
of	O
some	O
of	O
the	O
properties	O
of	O
regexes	B-Language
by	O
way	O
of	O
illustration	O
.	O
</s>
<s>
Also	O
worth	O
noting	O
is	O
that	O
these	O
regexes	B-Language
are	O
all	O
Perl-like	O
syntax	B-Application
.	O
</s>
<s>
Standard	O
POSIX	O
regular	B-Language
expressions	I-Language
are	O
different	O
.	O
</s>
<s>
Unless	O
otherwise	O
indicated	O
,	O
the	O
following	O
examples	O
conform	O
to	O
the	O
Perl	B-Language
programming	I-Language
language	I-Language
,	O
release	O
5.8.8	O
,	O
January	O
31	O
,	O
2006	O
.	O
</s>
<s>
This	O
means	O
that	O
other	O
implementations	O
may	O
lack	O
support	O
for	O
some	O
parts	O
of	O
the	O
syntax	B-Application
shown	O
here	O
(	O
e.g.	O
</s>
<s>
basic	O
vs.	O
extended	O
regex	B-Language
,	O
\( 	O
\	O
)	O
vs.	O
(	O
)	O
,	O
or	O
lack	O
of	O
\d	O
instead	O
of	O
POSIX	O
 [ :digit: ] 	O
)	O
.	O
</s>
<s>
The	O
syntax	B-Application
and	O
conventions	O
used	O
in	O
these	O
examples	O
coincide	O
with	O
that	O
of	O
other	O
programming	O
environments	O
as	O
well	O
.	O
</s>
<s>
or	O
{M,N}'d	O
regex	B-Language
that	O
comes	O
before	O
to	O
match	O
as	O
few	O
times	O
as	O
possible	O
.	O
</s>
<s>
print	O
"	O
The	O
non-greedy	O
match	O
with	O
'	O
l	O
 '	O
followed	O
by	O
one	O
or	O
"	O
;	O
</s>
<s>
The	O
non-greedy	O
match	O
with	O
'	O
l	O
 '	O
followed	O
by	O
one	O
or	O
more	O
characters	O
is	O
'	O
llo	O
 '	O
rather	O
than	O
'	O
llo	O
Wo	O
 '	O
.	O
</s>
<s>
\s	O
Matches	O
a	O
whitespace	O
character	O
,	O
which	O
in	O
ASCII	B-Protocol
are	O
tab	O
,	O
line	O
feed	O
,	O
form	O
feed	O
,	O
carriage	O
return	O
,	O
and	O
space	O
;	O
in	O
Unicode	O
,	O
also	O
matches	O
no-break	O
spaces	O
,	O
next	O
line	O
,	O
and	O
the	O
variable-width	O
spaces	O
(	O
amongst	O
others	O
)	O
.	O
</s>
<s>
\d	O
Matches	O
a	O
digit	O
;	O
same	O
as	O
 [ 0-9 ] 	O
in	O
ASCII	B-Protocol
;	O
in	O
Unicode	O
,	O
same	O
as	O
the	O
\p{Digit}	O
or	O
\p{GC=Decimal_Number}	O
property	O
,	O
which	O
itself	O
the	O
same	O
as	O
the	O
\p{Numeric_Type=Decimal}	O
property	O
.	O
</s>
<s>
\D	O
Matches	O
a	O
non-digit	O
;	O
same	O
as	O
 [ ^0-9 ] 	O
in	O
ASCII	B-Protocol
or	O
\P{Digit}	O
in	O
Unicode	O
.	O
</s>
<s>
print	O
"	O
a	O
,	O
b	O
,	O
and	O
c.	O
\n	O
 "	O
;	O
</s>
<s>
contains	O
a	O
character	O
other	O
than	O
a	O
,	O
b	O
,	O
and	O
c	B-Language
.	O
</s>
<s>
Regular	B-Language
expressions	I-Language
can	O
often	O
be	O
created	O
(	O
"	O
induced	O
"	O
or	O
"	O
learned	O
"	O
)	O
based	O
on	O
a	O
set	O
of	O
example	O
strings	O
.	O
</s>
<s>
This	O
is	O
known	O
as	O
the	O
induction	O
of	O
regular	B-General_Concept
languages	I-General_Concept
and	O
is	O
part	O
of	O
the	O
general	O
problem	O
of	O
grammar	B-Algorithm
induction	I-Algorithm
in	O
computational	O
learning	O
theory	O
.	O
</s>
<s>
Formally	O
,	O
given	O
examples	O
of	O
strings	O
in	O
a	O
regular	B-General_Concept
language	I-General_Concept
,	O
and	O
perhaps	O
also	O
given	O
examples	O
of	O
strings	O
not	O
in	O
that	O
regular	B-General_Concept
language	I-General_Concept
,	O
it	O
is	O
possible	O
to	O
induce	O
a	O
grammar	O
for	O
the	O
language	O
,	O
i.e.	O
,	O
a	O
regular	B-Language
expression	I-Language
that	O
generates	O
that	O
language	O
.	O
</s>
<s>
Not	O
all	O
regular	B-General_Concept
languages	I-General_Concept
can	O
be	O
induced	O
in	O
this	O
way	O
(	O
see	O
language	O
identification	O
in	O
the	O
limit	O
)	O
,	O
but	O
many	O
can	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
set	O
of	O
examples	O
{	O
1	O
,	O
10	O
,	O
100}	O
,	O
and	O
negative	O
set	O
(	O
of	O
counterexamples	O
)	O
{	O
11	O
,	O
1001	O
,	O
101	O
,	O
0}	O
can	O
be	O
used	O
to	O
induce	O
the	O
regular	B-Language
expression	I-Language
1⋅0*	O
(	O
1	O
followed	O
by	O
zero	O
or	O
more	O
0s	O
)	O
.	O
</s>
