[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Match-result submatch extraction is weird

This page is part of the web mail archives of SRFI 115 from before July 7th, 2015. The new archives for SRFI 115 contain all messages, not just those from before July 7th, 2015.

Hi all,

After clearing the initial roadblocks, I tried to use the library.
Being used to irregex I naively typed away and got this:

(define m (regexp-match '(seq ($ "x") "y") "xy"))
(rx-match-submatch m 1) => ERROR!

So, I looked up the syntax again and was confused:  why does the
rx-match-submatch procedure require the input string again?

(define m (regexp-match '(seq ($ "x") "y") "xy"))
(rx-match-submatch m "xy" 1) => "x"

That means I can do something completely bogus like the following, too!
(rx-match-submatch m "abc" 1) => "a"

This makes no sense, and I didn't see any rationale for this design.
It's also a step back from irregex, where the input string is kept
around in the match result object, and where you can simply extract it:

(define m (regexp-match '(seq ($ "x") "y") "xy"))
(irregex-match-substring m 1) => "x"