Update: Might be faster if possessive:>perl -wMstrict -le "my @suits = qw(D S C H); my $suits = join '', @suits; my $flush = qr{ ([$suits]) (?: [^$suits]+ \1){4} }xms; print $_, $_ =~ $flush ? ' flush' : ' nope' for '2H 3D 4C 5S 5H', '1H 2H 3H 4H 5H'; " 2H 3D 4C 5S 5H nope 1H 2H 3H 4H 5H flush
5.10 has possessive modifier:>perl -wMstrict -le "my @suits = qw(D S C H); my $suits = join '', @suits; my $flush = qr{ ([$suits]) (?: (?> [^$suits]+) \1){4} }xms; print $_, $_ =~ $flush ? ' flush' : ' nope' for '2H 3D 4C 5S 5H', '1H 2H 3H 4H 5H'; " 2H 3D 4C 5S 5H nope 1H 2H 3H 4H 5H flush
Bugfix: Changed (?> [^$suits])+ to (?> [^$suits]+) per ikegami Re^6: Simple Matching.>perl -wMstrict -le "my @suits = qw(D S C H); my $suits = join '', @suits; my $flush = qr{ ([$suits]) (?: [^$suits]++ \1){4} }xms; print $_, $_ =~ $flush ? ' flush' : ' nope' for '2H 3D 4C 5S 5H', '1H 2H 3H 4H 5H'; " 2H 3D 4C 5S 5H nope 1H 2H 3H 4H 5H flush
In reply to Re^5: Simple Matching
by AnomalousMonk
in thread Simple Matching
by rnroot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |