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

Re: new draft available

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.



On Sun, May 25, 2014 at 4:08 AM, John Cowan <cowan@xxxxxxxxxxxxxxxx> 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