Named Regex


examples/regex2/named_regex.p6
use v6;

my $phone = "054-1234567";

# You can also create named regexes:

my regex prefix { \d ** 2..3 }
my regex number { <+digit - [0]> \d ** 6 }
# if $phone ~~ m/^ <prefix> '-' <number> $/ {
# but this does not work now so we write the full syntax:
if $phone ~~ m/^ <prefix=&prefix> '-' <number=&number> $/ {
	say "prefix $/<prefix>  number: $/<number>";
}
# as you can see $/ is also a hash



Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC
If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed