[plt-scheme] Regexp partially matches alternate (unexpected)

From: Eli Barzilay (eli at barzilay.org)
Date: Thu May 13 23:29:19 EDT 2010

On May 13, Nadeem Abdul Hamid wrote:
> This result is what I expect:
> > (regexp-match #rx"(4)56|(.*)" "456")
> ("456" "4" #f)
> But, why does this partially match the first alternative, returning
> the clustered subexpression?...

This matches the first alternative completely.

> > (regexp-match #rx"(4)56|(.*)" "4ab")
> ("4ab" "4" "4ab")
> I would have expected to get:
> ("4ab" #f "4ab")

This looks like a bug -- I tried `git bisect', and it was introduced
in subversion r4379, which is now d3b96f936.

> Is there any way to achieve the latter? What I'm really matching
> against is something more like:
> > (regexp-match #px"(?:(?:(\\d)(\\d)(\\d))|(.*))" "4ab")
> ("4ab" "4" #f #f "4ab")
> and, in the event that there are not 3 digits, I would expect #f
> instead of the "4"?

(Yeah, it looks like the same problem.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.