|
From: | Hans Nowak |
Subject: | [Chicken-users] Re: Regex help. |
Date: | Sat, 01 Mar 2008 12:10:54 -0500 |
User-agent: | Thunderbird 2.0.0.0 (Macintosh/20070326) |
Peter Bex wrote:
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 ")
Disclaimer: I'm still rather new to Chicken, etc, but it seems to me that things would be clearer using a regex-literal:
#;6> (use regex-literals) ; loading /usr/local/lib/chicken/3/regex-literals.so ... #;7> (string-match #/^\\(.*)\s*$/ "\\foo ") ("\\foo " "foo ")Of course the .* match is greedy, so it matches any spaces after "foo" as well, which may or may not be your (Matthew's) intention. If not, this might work:
#;8> (string-match #/^\\(.*?)\s*$/ "\\foo ") ("\\foo " "foo") --Hans
[Prev in Thread] | Current Thread | [Next in Thread] |