[xquery-talk] string manipulation

John Snelson jsnelson at sleepycat.com
Mon Feb 6 00:13:54 PST 2006

Michael Kay wrote:
>>>>replace("book/title/author", "/.*?$", "")
>>>  Does this garantee to return "book/title" and not "book" ?  The
>>>longuest match would win, doesn't it ?  Personally, I'd use 
>>the regexp
>>>'/[^/]*$'.  BTW, why the '?' after the '*' ?
>>"*?" is a reluctant version of the "*" quantifier, meaning it matches 
>>the shortest sequence, rather than the longest. My regular expression 
>>works because of this - but yours will work as well.
> No, I don't think that "/.*?$" does work. The distinction between .* and .*?
> is that given several matches starting _at the same position_, .* will
> choose the longest while .*? chooses the shortest. But it won't cause
> backtracking to try and find a different match for the "/". 

I guess I didn't fully understand reluctant quantifiers then. Thanks for 
clarifying that.


John Snelson, Berkeley DB XML Engineer
Sleepycat Software, Inc

Contracted to Sleepycat through Parthenon Computing Ltd

More information about the talk mailing list