c:\@Work\Perl\monks>perl -wMstrict -le
"my $vowel = qr{ [AEIOUaeiou] }xms;
;;
my $s = 'xyzzyBARxkcdFOOyz';
;;
print 'offset of first vowel: ', $s =~ m{ (?= $vowel) }xms ? $+[0] : 'none';
print 'offset of last vowel: ', $s =~ m{ .* (?= $vowel) }xms ? $+[0] : 'none';
print 'offset of first vowel: ', 'XYZ' =~ m{ (?= $vowel) }xms ? $+[0] : 'none';
"
offset of first vowel: 6
offset of last vowel: 14
offset of first vowel: none
####
c:\@Work\Perl\monks>perl -wMstrict -le
"my $vowel = qr{ [AEIOUaeiou] }xms;
;;
my $s = 'aePDQioVWXua';
;;
print 'offset of first non-vowel: ', $s =~ m{ (?! $vowel) }xmsg ? pos($s) : 'none';
print 'offset of last non-vowel: ', $s =~ m{ .* (?! $vowel) }xmsg ? pos($s) : 'none';
;;
$s = 'aei';
print 'offset of first non-vowel: ', $s =~ m{ (?! $vowel) }xmsg ? pos($s) : 'none';
"
offset of first non-vowel: 2
offset of last non-vowel: 12
offset of first non-vowel: 3
##
##
c:\@Work\Perl\monks>perl -wMstrict -le
"my $non_vowel = qr{ [^AEIOUaeiou] }xms;
;;
my $s = 'aePDQioVWXua';
;;
print 'offset of first non-vowel: ', $s =~ m{ (?= $non_vowel) }xmsg ? pos($s) : 'none';
print 'offset of last non-vowel: ', $s =~ m{ .* (?= $non_vowel) }xmsg ? pos($s) : 'none';
;;
$s = 'aei';
print 'offset of first non-vowel: ', $s =~ m{ (?= $non_vowel) }xmsg ? pos($s) : 'none';
"
offset of first non-vowel: 2
offset of last non-vowel: 9
offset of first non-vowel: none