<s>
Raku	B-Language
rules	I-Language
are	O
the	O
regular	B-Language
expression	I-Language
,	O
string	B-Algorithm
matching	I-Algorithm
and	O
general-purpose	O
parsing	B-Language
facility	O
of	O
the	O
Raku	B-Application
programming	O
language	O
,	O
and	O
are	O
a	O
core	O
part	O
of	O
the	O
language	O
.	O
</s>
<s>
Since	O
Perl	B-Language
's	O
pattern-matching	O
constructs	O
have	O
exceeded	O
the	O
capabilities	O
of	O
formal	O
regular	B-Language
expressions	I-Language
for	O
some	O
time	O
,	O
Raku	B-Application
documentation	O
refers	O
to	O
them	O
exclusively	O
as	O
regexes	B-Language
,	O
distancing	O
the	O
term	O
from	O
the	O
formal	O
definition	O
.	O
</s>
<s>
Raku	B-Application
provides	O
a	O
superset	O
of	O
Perl	B-Language
5	O
features	O
with	O
respect	O
to	O
regexes	B-Language
,	O
folding	O
them	O
into	O
a	O
larger	O
framework	O
called	O
rules	O
,	O
which	O
provide	O
the	O
capabilities	O
of	O
a	O
parsing	B-Language
expression	O
grammar	O
,	O
as	O
well	O
as	O
acting	O
as	O
a	O
closure	B-Language
with	O
respect	O
to	O
their	O
lexical	O
scope	O
.	O
</s>
<s>
Anonymous	O
rules	O
can	O
be	O
introduced	O
with	O
the	O
regex	B-Language
(	O
or	O
rx	O
)	O
keyword	O
,	O
or	O
simply	O
be	O
used	O
inline	O
as	O
regexes	B-Language
were	O
in	O
Perl	B-Language
5	O
via	O
the	O
m	O
(	O
matching	O
)	O
or	O
s	O
(	O
substitution	O
)	O
operators	O
.	O
</s>
<s>
In	O
Apocalypse	O
5	O
,	O
a	O
document	O
outlining	O
the	O
preliminary	O
design	O
decisions	O
for	O
Raku	B-Application
pattern	O
matching	O
,	O
Larry	O
Wall	O
enumerated	O
20	O
problems	O
with	O
the	O
"	O
current	O
regex	B-Language
culture	O
"	O
.	O
</s>
<s>
Among	O
these	O
were	O
that	O
Perl	B-Language
's	O
regexes	B-Language
were	O
"	O
too	O
compact	O
and	O
'	O
cute	O
 '	O
"	O
,	O
had	O
"	O
too	O
much	O
reliance	O
on	O
too	O
few	O
metacharacters	O
"	O
,	O
"	O
little	O
support	O
for	O
named	O
captures	O
"	O
,	O
"	O
little	O
support	O
for	O
grammars	O
"	O
,	O
and	O
"	O
poor	O
integration	O
with	O
'	O
real	O
 '	O
language	O
"	O
.	O
</s>
<s>
Between	O
late	O
2004	O
and	O
mid-2005	O
,	O
a	O
compiler	O
for	O
Raku	B-Application
style	O
rules	O
was	O
developed	O
for	O
the	O
Parrot	B-Language
virtual	I-Language
machine	I-Language
called	O
Parrot	B-Language
Grammar	I-Language
Engine	I-Language
(	O
PGE	B-Language
)	O
,	O
which	O
was	O
later	O
renamed	O
to	O
the	O
more	O
generic	O
Parser	B-Language
Grammar	I-Language
Engine	I-Language
.	O
</s>
<s>
PGE	B-Language
is	O
a	O
combination	O
of	O
runtime	O
and	O
compiler	O
for	O
Raku	B-Application
style	O
grammars	O
that	O
allows	O
any	O
parrot-based	O
compiler	O
to	O
use	O
these	O
tools	O
for	O
parsing	B-Language
,	O
and	O
also	O
to	O
provide	O
rules	O
to	O
their	O
runtimes	O
.	O
</s>
<s>
Among	O
other	O
Raku	B-Application
features	O
,	O
support	O
for	O
named	O
captures	O
was	O
added	O
to	O
Perl	B-Language
5.10	O
in	O
2007	O
.	O
</s>
<s>
In	O
May	O
2012	O
,	O
the	O
reference	O
implementation	O
of	O
Raku	B-Application
,	O
Rakudo	B-Language
,	O
shipped	O
its	O
Rakudo	B-Language
Star	I-Language
monthly	O
snapshot	O
with	O
a	O
working	O
JSON	B-General_Concept
parser	O
built	O
entirely	O
in	O
Raku	B-Language
rules	I-Language
.	O
</s>
<s>
There	O
are	O
only	O
six	O
unchanged	O
features	O
from	O
Perl	B-Language
5	O
's	O
regexes	B-Language
:	O
</s>
<s>
A	O
handful	O
of	O
commit	O
operators	O
that	O
allow	O
the	O
programmer	O
to	O
control	O
backtracking	B-Algorithm
during	O
matching	O
.	O
</s>
<s>
The	O
following	O
changes	O
greatly	O
improve	O
the	O
readability	O
of	O
regexes	B-Language
:	O
</s>
<s>
Simplified	O
non-capturing	O
groups	O
:	O
[...],	O
which	O
are	O
the	O
same	O
as	O
Perl	B-Language
5	O
's	O
:	O
(?	O
:	O
...	O
)	O
</s>
<s>
Allows	O
for	O
whitespace	O
to	O
be	O
included	O
without	O
being	O
matched	O
,	O
allowing	O
for	O
multiline	O
regexes	B-Language
.	O
</s>
<s>
Extended	O
regex	B-Language
formatting	O
(	O
Perl	B-Language
5	O
's	O
/x	O
)	O
is	O
now	O
the	O
default	O
.	O
</s>
<s>
Some	O
of	O
the	O
features	O
of	O
Perl	B-Language
5	O
regular	B-Language
expressions	I-Language
are	O
more	O
powerful	O
in	O
Raku	B-Application
because	O
of	O
their	O
ability	O
to	O
encapsulate	O
the	O
expanded	O
features	O
of	O
Raku	B-Language
rules	I-Language
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Perl	B-Language
5	O
,	O
there	O
were	O
positive	O
and	O
negative	O
lookahead	O
operators	O
(?=	O
...	O
)	O
and	O
(	O
?!...	O
)	O
.	O
</s>
<s>
In	O
Raku	B-Application
these	O
same	O
features	O
exist	O
,	O
but	O
are	O
called	O
<before ...> and <!before ...>	O
.	O
</s>
<s>
However	O
,	O
because	O
before	O
can	O
encapsulate	O
arbitrary	O
rules	O
,	O
it	O
can	O
be	O
used	O
to	O
express	O
lookahead	O
as	O
a	O
syntactic	B-Application
predicate	I-Application
for	O
a	O
grammar	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
parsing	B-Language
expression	O
grammar	O
describes	O
the	O
classic	O
non-context-free	O
language	O
:	O
</s>
<s>
In	O
Raku	B-Language
rules	I-Language
that	O
would	O
be	O
:	O
</s>
<s>
However	O
,	O
this	O
makes	O
use	O
of	O
assertions	O
,	O
which	O
is	O
a	O
subtly	O
different	O
concept	O
in	O
Raku	B-Language
rules	I-Language
,	O
but	O
more	O
substantially	O
different	O
in	O
parsing	B-Language
theory	O
,	O
making	O
this	O
a	O
semantic	O
rather	O
than	O
syntactic	B-Application
predicate	I-Application
.	O
</s>
<s>
In	O
many	O
languages	O
,	O
regular	B-Language
expressions	I-Language
are	O
entered	O
as	O
strings	O
,	O
which	O
are	O
then	O
passed	O
to	O
library	O
routines	O
that	O
parse	B-Language
and	O
compile	O
them	O
into	O
an	O
internal	O
state	O
.	O
</s>
<s>
In	O
Perl	B-Language
5	O
,	O
regular	B-Language
expressions	I-Language
shared	O
some	O
of	O
the	O
lexical	B-Application
analysis	I-Application
with	O
Perl	B-Language
's	O
scanner	B-Application
.	O
</s>
<s>
This	O
simplified	O
many	O
aspects	O
of	O
regular	B-Language
expression	I-Language
usage	O
,	O
though	O
it	O
added	O
a	O
great	O
deal	O
of	O
complexity	O
to	O
the	O
scanner	B-Application
.	O
</s>
<s>
In	O
Raku	B-Application
,	O
rules	O
are	O
part	O
of	O
the	O
grammar	O
of	O
the	O
language	O
.	O
</s>
<s>
No	O
separate	O
parser	O
exists	O
for	O
rules	O
,	O
as	O
it	O
did	O
in	O
Perl	B-Language
5	O
.	O
</s>
<s>
This	O
means	O
that	O
code	O
,	O
embedded	O
in	O
rules	O
,	O
is	O
parsed	B-Language
at	O
the	O
same	O
time	O
as	O
the	O
rule	O
itself	O
and	O
its	O
surrounding	O
code	O
.	O
</s>
<s>
The	O
above	O
is	O
a	O
single	O
block	O
of	O
Raku	B-Application
code	O
that	O
contains	O
an	O
outer	O
rule	O
definition	O
,	O
an	O
inner	O
block	O
of	O
assertion	O
code	O
,	O
and	O
inside	O
of	O
that	O
a	O
regex	B-Language
that	O
contains	O
one	O
more	O
level	O
of	O
assertion	O
.	O
</s>
<s>
There	O
are	O
several	O
keywords	O
used	O
in	O
conjunction	O
with	O
Raku	B-Language
rules	I-Language
:	O
</s>
<s>
regex	B-Language
A	O
named	O
or	O
anonymous	O
regex	B-Language
that	O
ignores	O
whitespace	O
within	O
the	O
regex	B-Language
by	O
default	O
.	O
</s>
<s>
token	O
A	O
named	O
or	O
anonymous	O
regex	B-Language
that	O
implies	O
the	O
:ratchet	O
modifier	O
.	O
</s>
<s>
rule	O
A	O
named	O
or	O
anonymous	O
regex	B-Language
that	O
implies	O
the	O
:ratchet	O
and	O
:sigspace	O
modifiers	O
.	O
</s>
<s>
rx	O
An	O
anonymous	O
regex	B-Language
that	O
takes	O
arbitrary	O
delimiters	O
such	O
as	O
//	O
where	O
regex	B-Language
only	O
takes	O
braces	O
.	O
</s>
<s>
m	O
An	O
operator	O
form	O
of	O
anonymous	O
regex	B-Language
that	O
performs	O
matches	O
with	O
arbitrary	O
delimiters	O
.	O
</s>
<s>
s	O
An	O
operator	O
form	O
of	O
anonymous	O
regex	B-Language
that	O
performs	O
substitution	O
with	O
arbitrary	O
delimiters	O
.	O
</s>
<s>
/.../	O
Simply	O
placing	O
a	O
regex	B-Language
between	O
slashes	O
is	O
shorthand	O
for	O
rx/.../	O
.	O
</s>
<s>
Modifiers	O
may	O
be	O
placed	O
after	O
any	O
of	O
the	O
regex	B-Language
keywords	O
,	O
and	O
before	O
the	O
delimiter	O
.	O
</s>
<s>
If	O
a	O
regex	B-Language
is	O
named	O
,	O
the	O
modifier	O
comes	O
after	O
the	O
name	O
.	O
</s>
<s>
Modifiers	O
control	O
the	O
way	O
regexes	B-Language
are	O
parsed	B-Language
and	O
how	O
they	O
behave	O
.	O
</s>
<s>
:s	O
or	O
:sigspace	O
Replace	O
whitespace	O
in	O
the	O
regex	B-Language
with	O
a	O
whitespace-matching	O
rule	O
,	O
rather	O
than	O
simply	O
ignoring	O
it	O
.	O
</s>
<s>
:Perl5	O
Treat	O
the	O
regex	B-Language
as	O
a	O
Perl	B-Language
5	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
:ratchet	O
Never	O
perform	O
backtracking	B-Algorithm
in	O
the	O
rule	O
.	O
</s>
<s>
This	O
is	O
the	O
grammar	O
used	O
to	O
define	O
Perl	B-Language
's	O
sprintf	O
string	O
formatting	O
notation	O
.	O
</s>
<s>
Here	O
are	O
some	O
example	O
rules	O
in	O
Raku	B-Application
:	O
</s>
