If you want to avoid scary experimental features, the "classic" way to do this is by composition:
See perlre, perlretut, and perlrequick.c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $rx_vowel = qr{ [aeiouAEIOU] }xms; my $rx_cons = qr{ (?! $rx_vowel) [[:alpha:]] }xms; ;; my $rx_cvc = qr{ \b $rx_cons $rx_vowel $rx_cons \b }xms; ;; my $s = 'when did the cop get his cap and tape and run out too?'; my @captures = $s =~ m{ $rx_cvc }xmsg; dd \@captures; " ["did", "cop", "get", "his", "cap", "run"]
Update 1: Changed example string slightly to highlight difference between "cap" and "tape" (was "cape").
Update 2: Another ancient way to do this purely with character classes may be slightly faster because it avoids a lookaround:
Note, however, the tricky double-negative [^[:^alpha:]\Q$vowel\E] in $rx_cons: "not not-an-alpha or a vowel". See "The POSIX character class syntax" in perlre.c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $vowel = 'aeiouAEIOU'; my $rx_vowel = qr{ [\Q$vowel\E] }xms; my $rx_cons = qr{ [^[:^alpha:]\Q$vowel\E] }xms; ;; my $rx_cvc = qr{ \b $rx_cons $rx_vowel $rx_cons \b }xms; ;; my $s = 'when did the cop get his cap and tape and run out too?'; my @captures = $s =~ m{ $rx_cvc }xmsg; dd \@captures; " ["did", "cop", "get", "his", "cap", "run"]
Give a man a fish: <%-{-{-{-<
In reply to Re: User name character classes
by AnomalousMonk
in thread User name character classes
by Zenzizenzizenzic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |