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+ $ }



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