chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Regex help.


From: Peter Bex
Subject: Re: [Chicken-users] Regex help.
Date: Sat, 1 Mar 2008 12:32:46 +0100
User-agent: Mutt/1.4.2.3i

On Sat, Mar 01, 2008 at 04:21:16AM -0700, Matthew Welland wrote:
> What am I not getting here?
> 
> DB<1> "\\foo "=~m/^\\(.*) $/;print $1;
> foo
> 
> irb> "\\foo ".match(/^\\(.*)\s*$/);puts $1
> foo
> 
> csi> (string-match (regexp "^\\(.*)\\s*$") "\\foo ")
> #f

It tells me
Error: (regexp) cannot compile regular expression - unmatched parentheses

In chicken, you're doing the equivalent of Ruby's
"\\foo ".match(/^\(.*)\s*$/)

So, to get two backslashes in the string, use four of them;
one to escape the first, one to escape the second, resulting in
two backslashes which count for the regex as one escaped backslash.

#;2> (string-match (regexp "^\\\\(.*)\\s*$") "\\foo ")
("\\foo " "foo ")

HTH,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

Attachment: pgpr70H1H20BJ.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]