Andreas Bernauer <andreas.bernauer@gmx.de> writes:
> Hi,
>
> I was playing with scsh's (King Conan) regex machinery and found a
> strange a behavior. I think it's a bug, but maybe I am missing
> something.
>
> Isn't the last example supposed to return "31/12/0431/12/04"? The
> example is adopted from the scsh manual
> http://www.scsh.net/docu/html/man-Z-H-7.html#node_idx_1148
>
> (let ((s "12/31/04 12/31/04"))
> (regexp-substitute/global #f (rx (submatch (+ digit)) "/" ; 1 = M
> (submatch (+ digit)) "/" ; 2 = D
> (submatch (+ digit))) ; 3 = Y
> s ; Source string
> 'pre 2 "/" 1 "/" 3 'post))
>
> ==> "31/12/04 31/12/04"
>
> but
>
> (let ((s "12/31/0412/31/04"))
> (regexp-substitute/global #f (rx (submatch (+ digit)) "/" ; 1 = M
> (submatch (+ digit)) "/" ; 2 = D
> (submatch (+ digit))) ; 3 = Y
> s ; Source string
> 'pre 2 "/" 1 "/" 3 'post))
> ==> "31/12/0412/31/04"
>
> although the regexp does not "eat" any whitespace. It looks like
> regexp-substitute/global eats the whitespace accidently.
Sorry, but I don't think I understand your problem: there is no
whitespace in the last example and as your regexp matches "0412" as a
whole, REGEXP-SUBSTITUTE/GLOBAL will apply the substitution only
once and replace "12/31/0412" by "31/12/0412".
--
Martin
|