From chang at saitama-med.ac.jp Fri Aug 15 07:50:43 2008 From: chang at saitama-med.ac.jp (=?ISO-2022-JP?B?GyRCRCUhITRBPSgbKEI=?=) Date: Fri, 15 Aug 2008 16:50:43 +0900 Subject: [cl-ppcre-devel] Question about a strange behavior of cl-ppcre Message-ID: <48A53553.9080907@saitama-med.ac.jp> Hello, I post this question because the description of this mailing list says that this is the place to post a question about cl-ppcre. I am a user of cl-ppcre on sbcl. I just re-installed cl-ppcre on sbcl, so I guess the version of cl-ppcre is the newest one. I found a strange behavior as below. CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\")) \ CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\\\")) \ CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\\\\\\\")) \\ For me, it is very difficult to figure out what's going on. Would someone kindly help me understand this problem? Han-Soo From edi at agharta.de Fri Aug 15 14:29:49 2008 From: edi at agharta.de (Edi Weitz) Date: Fri, 15 Aug 2008 16:29:49 +0200 Subject: [cl-ppcre-devel] Question about a strange behavior of cl-ppcre In-Reply-To: <48A53553.9080907@saitama-med.ac.jp> =?shift_jis?b?KA==?= =?shift_jis?b?kqOBQIq/j0cn?= =?shift_jis?b?cw==?= message of "Fri, 15 Aug 2008 16:50:43 +0900") References: <48A53553.9080907@saitama-med.ac.jp> Message-ID: On Fri, 15 Aug 2008 16:50:43 +0900, ???? wrote: > CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\")) > \ > CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\\\")) > \ > CL-USER> (format t "~A" (cl-ppcre:regex-replace "a" "a" "\\\\\\\\")) > \\ The backslash in the replacement specification is special - it can be followed by things like #\& or #\` to denote specific parts of the target string - see documentation. So, if you just want to have a backslash, you need two backslashes in order to avoid confusion: CL-USER 1 > (ppcre:regex-replace "a" "xay" "\\&\\&") "xaay" T CL-USER 2 > (ppcre:regex-replace "a" "xay" "\\&\\\\&") "xa\\&y" T Your second example is one (escaped) backslash, your third example consists of two (escaped) backslashes. This is conforming with Perl: edi at miles:~$ perl -le '$_ = "a"; s/a/\\/; print' \ edi at miles:~$ perl -le '$_ = "a"; s/a/\\\\/; print' \\ In your first example, there's only one backslash, but as there's nothing following it, the parser figured out that you probably meant a backslash. This is some kind of a DWIM behaviour and you can of course argue if it's a good thing or not. HTH, Edi.