chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Regex help.


From: Matthew Welland
Subject: Re: [Chicken-users] Regex help.
Date: Sat, 1 Mar 2008 09:33:05 -0700
User-agent: KMail/1.9.6 (enterprise 0.20070907.709405)

Thanks. It didn't help that I was not getting the compile error:

csi> (define r (regexp "^\\(.*)\\s*$"))
csi>

This is what I actually wanted:

(define esc-regex  (regexp "^\\\\([^\\s]+)\\s*$"))

Thanks

On Saturday 01 March 2008 04:32:46 am Peter Bex wrote:
> 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://www.kiatoa.com, fight for a better world.




reply via email to

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