Perl 6 An Introduction to Perl 6 #29

Named regular expressions

Create named regular expressions:

regex number { \d+ [ '.' \d+ ]? }

my $a = "I owe you 3.45 euros";
if ($a ~~ / <number> /)  { say $/; }     # "3.45"

Combine them:

regex sigil { '$' | '@' | '%' | '&' }

regex ident { [ <alpha> | '_' ] \w* }

regex name { <ident> [ '::' <ident> ]* }

regex variable { <sigil> <name> }
Copyright © 2008 Patrick Michaud