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

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Thu May 13 21:19:10 EDT 2010

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?...

> (regexp-match #rx"(4)56|(.*)" "4ab")
("4ab" "4" "4ab")

I would have expected to get:
("4ab" #f "4ab")

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"?

--- nadeem

Posted on the users mailing list.