'1,2,3' ~~ / \d+ % ',' /;
my $ingredients = 'milk, flour, eggs and sugar';
$ingredients ~~ m/ [\w+]+ % [\,\s*] / && say "|$/|";
'1,2,3' ~~ / \d+ % ',' / && say "|$/|";
my @a = (
'15179736712334102823,15203307381943332421,152033062464592402',
'11230282334151797361',
'12334105179128237367,1152033073819433324',
'12334105179128237367,1152033073819433324###'
);
.say if /^ [\d+]+ % ',' $ / for @a;
if 'abc' ~~ m/(.) <alpha> (.) / {
say $/.caps.WHAT;
my @a = $/.caps;
say @a;
say " -> 这次匹配有 @a.elems() 个 Pair";
for $/.caps {
say .key, ' => ', .value.Str;
}
}
my $s = 'the quick brown fox jumped over the the lazy dog';
if $s ~~ m/ << (\w+) \W+ $0 >> / {
say "Found '$0' twice in a row";
say "Found '$/[0]' twice in a line"
}
my $ingredients = 'eggs, milk, sugar and flour';
if $ingredients ~~ m/(\w+)+ % [\,\s*] \s* 'and' \s* (\w+)/ {
say 'list: ', $/[0].join(" | ");
say 'end: ', "$/[1]";
say $/.elems;
say $/[0].WHAT;
say $/[0].elems;
}
my $str = 'Germany was reunited on 1990-10-03, peacefully';
if $str ~~ m/ (\d**4) \- (\d\d) \- (\d\d) / {
say $/.WHAT;
say $/.elems;
say 'Year: ',"$/[0]";
say 'Month: ',"$/[1]";
say 'Day: ',"$/[2]";
say $/.join('-');
}
my $s = 'the quick brown fox jumped over the the lazy dog';
my regex word { \w+ [ \' \w+ ]? }
my regex dup { « <danci=&word> \W+ $<danci> » }
if $s ~~ m/ <dupword=&dup> / {
say "Found '{$<dupword><danci>}' twice in a row";
say $/;
}
my regex number { \d+ [ \. \d+]? }
my token ident { \w+ }
my rule alpha { <[A..Za..z]> }
say so "12.34" ~~ &number;
say so "12.88 + 0.12" ~~ / <number> \s* '+' \s* <number> /;
grammar EquationParse {
token TOP { <number> \s* '+' \s* <number> \s* '=' \s* <number> }
}
my $expr = EquationParse.parse("12.88 + 0.12 = 13.00");
say $expr;
my @matches = @*ARGS.map( {$^þ ~~ m:g/\* ~ \* (\w+)/} );
say @matches.map: { $^þ.perl ~ "\n" };
my $a-regex = /^þ/;
say 'þor' ~~ $a-regex;
my $ð = 'ð';
my $var-regex = rx/$ð $/;
say 'buð' ~~ $var-regex;
my $d = $ð;
my $no-var-regex = /$d u/;
say 'ðu' ~~ $no-var-regex;
$_ = 'ðu';
say "Matching contextual variable";
say rx/.u/;
say m/ð./;
say "Variable that inmediately matches contextual variable";
my $not-a-var = m/ð./;
$_ = 'another context';
say $not-a-var;
say "Matching string";
say 'ðu' ~~ rx/.u/;
say 'ðu' ~~ m/ð./;
given 'ABBBCDEEF' {
.comb(/\w+ % <same>/).say;
}
given '2_2020_000987 column=d:bcp_soc, timestamp=1605155065124, value=42.0' {
.comb( / ^ [\d+]+ % '_' | <?after d\:> \w+ | <?after value\=> .*/ ).say
}
given 'a33|b44=c55|' {
.comb(/ \d+ <?before '|' | '='> /).say
}