On Sun, Sep 29, 2013 at 10:59 AM, Robert Klemme
<shortcutter / googlemail.com>wrote:

> f
> fo
> => "foo"
> irb(main):003:0> "foo".scan /(?=\w)/ do puts $`.length end
> 0
> 1
> 2
> => "foo"
>
> As you can see, with a trick you even get to know the matching positions.
> :-)


Ahh, I had been trying to think of a way to do that. :) Thank you for that
trick.


> I usually recommend "Mastering Regular Expressions" - even though it's
> not an introductory book.


Yes, I also recommend that book.  ;)  I have had it for years, but much of
it
does not "stick to my brain."


> If you want to see the matching process at
> work you can use http://weitz.de/regex-coach/ (Windows program but
> works with WINE on Linux).  That helps understanding the matching
> process - you can even single step.


That sounds cool. I've sometimes wished there was an Onigmo patch
to allow that sort of thing.

Imagine regular expressions debuggable at runtime... or maybe the real
experts would cringe at that thought.  :)

Anyway: About lookarounds. As I see it, there are four basic cases,
arising from two basic questions: 1) Is the nonconsuming match before or
after the consuming one? and 2) is the nonconsuming match positive or
negative?

I read an article that (sort of) implied that there might be eight cases --
but
I think I have convinced myself this was a notational issue.

As this relates to Regexador -- I am thinking of introducing three new
keywords (find, with, without) so that lookarounds would work this way:

    find X with Y       # /(?=XY)X/     - pos lookahead
    find X without Y    # /(?!=XY)X/    - neg lookahead
    with X find Y       # /(?<=X)Y/      - pos lookbehind
    without X find Y    # /(?<!X)Y/     - neg lookbehind

But there are some slight subtleties I am working through here.

For example, I have read that most engines require a lookbehind to be
a fixed-length expression (with .NET and ABA being exceptions -- and I
don't even know what ABA is).

I've confirmed that Ruby 2.0 doesn't allow variable-length lookbehinds.

Hal