[cl-ppcre-devel] searching backward?

Edi Weitz edi at agharta.de
Fri Feb 16 08:19:17 UTC 2007


On Thu, 15 Feb 2007 20:27:45 -0800, Shawn Betts <sabetts at vcn.bc.ca> wrote:

> Is there a way to search backward through a string? 
>
> * (ppcre:scan "abc" "111abc1111abc11")
>
> 3
> 6
> #()
> #()
> * (ppcre:scan "abc" "111abc1111abc11" :start 15 :end 0)
>
> NIL
>
> I tried just making end < start which doesn't seem to work :). I
> suppose what i'm looking for is the equivalent of :from-end that
> most cl sequence functions have.

No, there's no such thing as a :FROM-END keyword argument or the
equivalent, and I'm also not aware of a regex facility in another
programming language which has that.

If you really need it, you could loop through the string applying SCAN
until it matches with decreasing values for START, but that could be
quite inefficient, of course.  An alternative would be to work on
(REVERSE TARGET) instead of TARGET, but you'll have to think hard how
your regular expression should look like in that case - the semantics
of things like "*" will certainly be different.

Cheers,
Edi.



More information about the Cl-ppcre-devel mailing list