Camelia
Prev: Rules

Tokens

examples/regex2/tokens.p6
use v6;

# Let's see something else
my $good = 'this_is_a_long_variable = 456 + 789';
my $bad  = 'this_is_a_long_variable = 456 +';

for $good, $bad -> $exp {
    if $exp ~~ m/:s ^ \w+ \= \d+ \+ \d+ $/ {
        say "Match: $exp";
    }
}

# mark the quantifyers as not backtracking

# m/:s ^ \w+: \= \d+: \+ \d+: $/ {

# or use the :ratchet modifier to set all the 
# quantifiers non-backtracking

# m/:s :ratchet ^ \w+ \= \d+ \+ \d+ $/ {

# and there is a special name for this called token

my token sentence { ^ \w+ \= \d+ \+ \d+ $ }



Prev: Rules

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: