I am trying to build a regex to extract vowels and consonants from a
string. So far, I am able to extract the basic a-e-i-o-u sequence
using the following extension to the String class:
"Mary had a little lamb".vowels
"Mary had a little lamb".consonants
However, the regex does not accommodate the conditional treatment of
'y' as a vowel *if there is no other vowel before or after it.* If
properly implemented, the previous examples would return: ayaaiea
(vowels) and mrhdlttllmb (consonants).
According to this post (http://www.perlmonks.org/?node_id=592867),
this could be accommodated in Perl using "zero-width negative-look-
behind" and "zero-width negative-look-ahead" assertions as follows:
my @vowels = ( /[aeiou]|(?<![aeiou])y(?![aeiou])/gi );
Where, the "(?<!...)" is a "zero-width negative-look-behind assertion"
and the "(?!...)" is a "zero-width negative-look-ahead assertion".
I have since discovered that Ruby 1.8 lacks regex look-behind
assertion so one can't simply translate this code fragment to Ruby
So, the question is: how can I accomplish the end result in Ruby (a-e-
i-o-u + the conditional treatment of 'y' as a vowel *if there is no
other vowel before or after it.*) ? Any thoughts are appreciated.