On Thu, 13 May 2004 20:56:55 +0900, nobu.nokada wrote:

> Hi,
> 
> At Wed, 12 May 2004 09:13:51 +0900,
> Florian Gross wrote in [ruby-talk:99884]:
>> > Yes, that would clarify the situation, but is it the correct
>> > behaviour?  I would think that (?!a)a doesn't mean the same
>> > character, but consecutive ones.  Because it doesn't consume
>> > the character, it effectively is the character 'before' the
>> > match (if any).  The other behaviour wouldn't make sense,
>> > because (?!a)b is then exactly the same as b.
>> 
>> I think that it's the intended behavior. Just use /(?!a).b/ if you want 
>> to consume the character.
>> 
>> Thinking about this, it is indeed possible to implement fixed-width 
>> look-behind -- interesting.
> 
> Ruby 1.9 (Oniguruma) has look-behind feature.
> 
>   $ ruby -v -e 'p "bab".gsub(/(?<!a)ab/, "cd")'
>   ruby 1.9.0 (2004-05-12) [i686-linux]
>   "bcd"

Great!

That is exactly what I needed.  And I saw it has negative
look behind also. (?<!subexp)
I think this is especially usefull in String#gsub, so you don't
have to subgroup the context, and replicate it in the
substitution.

Kristof