[plt-scheme] Odd behavior in regexp-replace (299.25-cvs4jan2005)

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Jan 4 19:05:12 EST 2005

The "strings" in the documentation correspond to the actual characters
in the string (as returned by, say, string-ref) not their Scheme
representation. So, this phrase:

  If a ``\'' is followed by anything other than a digit, ``&'', ``\'',
  or ``$'', then it is treated as ``\0''.

means that the string "\\red{}" is interpreted as "\\0red{}", since the
string only contains a single character #\\ in it. If you want to
actually replace the entire match, you must avoid having any

  #\\

characters in your string, or you must escape them:

  A literal ``&'' or ``\'' is specified as ``\&'' or ``\\'', respectively.

ie, like you've done below. Or, like this:

  (string #\\ #\\)

The whole thing is definitely confused by the fact that you have to
escape the backslashes twice: once for scheme string syntax and once
for the library processing the string. Maybe we need to string boxes.

Robby

At Tue, 4 Jan 2005 17:57:39 -0500, Richard Cobbe wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Welcome to MzScheme version 299.25, Copyright (c) 2005 PLT Scheme, Inc.
> > (printf "~a~n" (regexp-replace ">>" "abc>>def" "\\red{}"))
> abc>>red{}def
> > (printf "~a~n" (regexp-replace ">>" "abc>>def" "\\\\red{}"))
> abc\red{}def
> 
> I don't understand this -- why should I have to escape the backslash in
> order to ensure that the >> is removed from the original string?  Or is
> this a bug in regexp-replace that interprets "\\red{}" as though it were
> "\\0red{}"?
> 
> In either case, the observed behavior doesn't match (my interpretation
> of) the documentation.
> 
> Thanks,
> 
> Richard



Posted on the users mailing list.