chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] string-match-positions


From: Jim Ursetto
Subject: Re: [Chicken-users] string-match-positions
Date: Sun, 1 Feb 2009 19:33:50 -0600

> On Sun, Feb 1, 2009 at 12:06 PM, Jörg F. Wittenberger
>> But worst regex.scm:
>> (define (string-match-positions rx str)

That performs an anchored match against the beginning and end of the
entire string.  If you want to provide a range to search in, use:

(string-search-positions rx str #!optional (start 0) (range
(string-length str)))

You can anchor to the beginning of the offset.  For example:

#;18> (string-search "^cd" "abcdefg" 2)
("cd")
#;19> (string-search "^cd" "abcdefg" 1)
#f
#;20> (string-search "^[a-z]+" "abcdefg" 1 3)
("bcd")

It doesn't work to anchor to the end of the range, though:

#;21> (string-search "^[a-z]+$" "abcdefg" 1 3)
#f

Not sure if that is a bug.

Note that in the past, a string-search anchored to the start position
didn't work, and string-match with an offset often returned garbage:

#;23> (string-search "^[a-z]+" "abcdefg" 1 3)
#f
#;21> (string-match "." "abcdefg" 1)
("g")       ; what?
#;14> (string-match "bc" "abcdefg" 1)
#f

That was tested with 3.3.10--it might not have been fixed until the
irregex merge.  So, I am not sure you saw reasonable behavior in the
past anyway.

Jim




reply via email to

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