Camelia
Prev: Capture

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



Prev: Capture

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: