10.2. Simple matching

In Perl 6 the smart match ~~ operator 
is used for regex matching.

For negative matching use the !~~ operator.

Example 10-1. examples/regex/simple.p6

#!/usr/bin/perl6
use v6;


my $str = 'abc123';

if ($str ~~ /a/) {
	say "Matching";
}

if ($str !~~ /z/) {
	say "No z in $str";
}

Example 10-2. examples/regex/special_chars.p6

#!/usr/bin/perl6
use v6;


my $str = 'abc = 123';

if ($str ~~ /\=/) {
	say "Matching";
}

If you are interested in on-site trainings by the author, please contact me directly.

Online courses: