On Fri, 15 Aug 2008 16:50:43 +0900, 張 漢秀 chang@saitama-med.ac.jp 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@miles:~$ perl -le '$_ = "a"; s/a/\/; print' \ edi@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.