in reply to User name character classes
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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: User name character classes
by haukex (Archbishop) on Feb 22, 2019 at 20:00 UTC | |
by AnomalousMonk (Archbishop) on Feb 22, 2019 at 20:10 UTC | |
by haukex (Archbishop) on Feb 22, 2019 at 20:11 UTC | |
|
Re^2: User name character classes
by Zenzizenzizenzic (Pilgrim) on Feb 26, 2019 at 21:57 UTC |