Yes, the original mistake was mine. I have since updated that node. I don't know any slick way of putting it all in one character class, though with lookahead it could be wedged into one regex.
Update: here's my first shot at a lookahead version:
my @strings = qw( aaaaa eeeee iiiii abcde aeiou bdfhj ); my $range = 'AaEeIiOoUu'; my $alt = join '|', split //, $range; my %regexes = ( alternation => qr/$alt/, class => qr/[$range]/, lookahead => qr/([$range])((?!\1)[$range])((?!\2)[$range])((?!\3 +)[$range])((?!\4)[$range])/, ); foreach my $string (@strings) { print "$string:\n"; while (my ($k, $r) = each %regexes) { print "\t$k - " . ($string =~ /$r/ ? 'YES' : 'NO') . $/; } }
And the output:
aaaaa: alternation - YES class - YES lookahead - NO eeeee: alternation - YES class - YES lookahead - NO iiiii: alternation - YES class - YES lookahead - NO abcde: alternation - YES class - YES lookahead - NO aeiou: alternation - YES class - YES lookahead - YES bdfhj: alternation - NO class - NO lookahead - NO
In reply to Re^7: $_ works, $my_variable doesn't?
by revdiablo
in thread $_ works, $my_variable doesn't?
by C_T
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |