Camelia
Prev: Perl 6 Regexes

Regexes in Perl 6

You can still use m// as a regex but as you can see spaces in the regex are non significant. It is quite similar to the effect of /x option in PCRE.

~~!~~
 operator.
examples/regex2/simple.p6
use v6;

my $text = "Learning regexes";
if $text ~~ m/ regex / {
    say "This is about regexes!";
}

if $text !~~ m/ foobar / {
    say "No foobar in $text";
}
Regex in Perl 6 disregard spaces by default. People who are used to the Perl 5 style regular expressions - which means basically every programming language that has a regular expression library - will usuall think as spaces being significant in the regular expressions. We will have to unlearn that and think about the individual bits and pieces that are the tokens we would like to match. Basically Perl 6 regexes work as if you always had the /x modifyer on which in Perl 5 means disregard spaces and treat # as start of comment.

Prev: Perl 6 Regexes

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: