Re: Question about CL-PPCRE

Martin Simmons <[email protected]> Wed, 24 Jun 2026 13:06:10 +0100
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
No, it's not just that because the unexpected result is also being printed by
Lisp so will get doubled up again.

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/



>>>>> On Wed, 24 Jun 2026 03:53:34 -0700, David McClain said:
> 
> Isn’t this just Lisp’s natural semantics in strings? If you want a backslash \ in a string, you need to double them up. CL-PPCRE can only see what remains in a string after Lisp has had its go at it. 
> 
> This is why Emacs and LW regexps are so injurious to vision.  I find that CL-PPCRE is generally less noxious because it doesn’t depend on backslash for critical regexp elements. 
> 
> > On Jun 24, 2026, at 03:07, Martin Simmons <[email protected]> wrote:
> > 
> >>>>>> On Tue, 23 Jun 2026 20:47:32 +0200, Marco Antoniotti (as marco dot antoniotti at unimib dot it) said:
> >> 
> >> Hi
> >> 
> >> I am sure I missed something in the CL-PPCRE documentation, but here it is.
> >> 
> >> I am fooling around with a C tokenizer and I am running into the following
> >> problem.
> >> 
> >> The string esre contains the "escape sequences" for C (and Perl, etc etc)
> >> 
> >> CL Prompt > esre
> >> "(\\\\(['\\\"\\?\\\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))"
> >> 
> >> If I use CL-PPCRE:REPLACE-ALL I get the following (I tried to boil it down):
> >> 
> >> CL Prompt > (regex-replace-all "\\$<ES>" "/$<ES>/" esre)
> >> "/(\\(['\\\"\\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))/"
> >> T
> >> 
> >> Apart from the bounding slashes, I would have expected the result of
> >> CL-PPCRE:REPLACE-ALL not to return a shorter string.
> >> 
> >> What exactly (backslash escaping for sure) am I missing?
> > 
> > It looks like an undocumented feature of the replacement string: \\ is
> > converted to a single backslash by CL-PPCRE::BUILD-REPLACEMENT-TEMPLATE.  That
> > means it will always return a shorter string when \\ is present in the
> > replacement string and if you want \\ in the output then you'll need to use
> > \\\\ (i.e. 8 backslashes in the Lisp syntax of that string!).
> > 
> > Also, to make it more confusing, if \ is followed by anything other than \ & `
> > ' digits or {digits} then it is also treated as a single backslash.  i.e. \a
> > is \a.
> > 
> > -- 
> > Martin Simmons
> > LispWorks Ltd
> > http://www.lispworks.com/
> > 
> > _______________________________________________
> > Lisp Hug - the mailing list for LispWorks users
> > [email protected] <mailto:[email protected]>
> > http://www.lispworks.com/support/lisp-hug.html
> 
> 

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html