On Sun, May 25, 2014 at 4:08 AM, John Cowan <xxxxxx@mercury.ccil.org> wrote:

Maybe `regex-replace` should accept an optional integer argument
indicating which occurrence in the main string to replace.

I've implemented this in the reference implementation:

(test "-abc \t\n d ef  "
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0))
(test "-abc \t\n d ef  "
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0 #f 0))
(test "  abc-d ef  "
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0 #f 1))
(test "  abc \t\n d-ef  "
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0 #f 2))
(test "  abc \t\n d ef-"
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0 #f 3))
(test "  abc \t\n d ef  "
    (regexp-replace '(+ space) "  abc \t\n d ef  " "-" 0 #f 4))
(test " abc d ef " (regexp-replace-all '(+ space) "  abc \t\n d ef  " " "))

There are three optional positional parameters which is
a little on the unwieldy side:

  (regexp-replace re str subst [start end count])

but for ease of use I'm allowing #f for the end (0 is short
enough for the start).

-- 
Alex