On Feb 2, 4:36=A0pm, Donovan Dillon <donovan.dil... / verizon.net> wrote:
> Thanks Robert, Corey, Philip, Stephano, et. al, for all of the great
> suggestions. However, they all seem to ignore the conditional nature of 'y=
'
> as a vowel. I would like the regex to treat 'y' as a vowel when there is n=
o
> other vowel either before or after it. The string I used initially, was
> drawn from the following perl code that accomplishes this (found athttp://=
www.perlmonks.org/?node_id=3D592867):
>
> my @vowels =3D ( /[aeiou]|(?<![aeiou])y(?![aeiou])/gi );
>
> The "(?<!...)" is a "zero-width negative-look-behind assertion".
>
> The "(?!...)" is a "zero-width negative-look-ahead assertion".
>
> Together, they match the condition of treating "y as a vowel only if there=

> is no other vowel before or after it."
>
> This was my attempt at converting the Perl fragment to Ruby syntax:
>
> scan(/[aeiou]|(?![aeiou])y(?![aeiou])/i)
>
> I have since discovered that Ruby 1.8 lacks regex look-behind assertion --=

> which explains why the code was failing. As a result, I have fallen back t=
o
> the following which currently ignores the 'y':
>
> class String
> =A0 def vowels
> =A0 =A0 scan(/[aeiou]/i)
> =A0 end
> =A0 def consonants
> =A0 =A0 scan(/[^aeiou]/i)
> =A0 end
> end
>
> Any ideas how to modify this to include the conditional treatment of "y as=
 a
> vowel only if there is no other vowel before or after it?"
>
> (i.e., is there a way to simulate the perl "zero-width negative-look-behin=
d"
> and "zero-width negative-look-ahead" assertions for 'y' in Ruby 1.8?)
>
> On 2/2/08 4:17 PM, in article
> 335e48a90802021417n4ba96a11i746bd5118f184... / mail.gmail.com, "Robert Dober=
"
>
> <robert.do... / gmail.com> wrote:
> > Oh sorry using 1.9 excluseviley now...
> > Robert

Origumura is the default regex library for Ruby 1.9. It includes look-
behind assertions (wohoo!) ... and ... It turns out that there is a
gem available so you don't have to upgrade to Ruby 1.9 or monkey
around with creating a custom Ruby 1.8.x build.

The gem relies upon a c library that can be downloaded from here:
http://www.geocities.jp/kosako3/oniguruma/

After installing the library, origuruma installation is a breeze
using:

sudo gem install -r origuruma

However, my progress has come to a screeching halt as I am now
receiving the following error:


** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
Exiting
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require': ./lib/string_extensions.rb:4: undefined
(?...)
sequence: /[aeiou]|(?<![aeiou])y(?![aeiou])/ (SyntaxError)
=2E/lib/string_extensions.rb:8: undefined (?...) sequence: /![aeiou]|(?
<=3D[aeiou])y(?=3D[aeiou])/      from /usr/local/lib/ruby/site_ruby/1.8/
rubygems/custom_require.rb:27:in `require'

It seems to be complaining about the look-behind and look-ahead
assertions in the following code fragment (which origuruma is supposed
to support):


class String
  def vowels
    scan(/[aeiou]|(?<![aeiou])y(?![aeiou])/i)
  end
  def consonants
    scan(/![aeiou]|(?<=3D[aeiou])y(?=3D[aeiou])/i)
  end
end

According to this reference (http://www.geocities.jp/kosako3/
oniguruma/
doc/RE.txt), the look behind and look ahead syntax that I am using
appears to be correct
(ref section 7. Extended groups).

This suggests either:

A. Ruby may be using the default regexp library instead of the
oniguruma regexp library,

B. The oniguruma regexp library is not accessible via the 'scan'
method, or

C. Something else entirely

=2E.. hmmm ... <scratches head/>

Any suggestions?