[xquery-talk] string manipulation
mhk at mhk.me.uk
Sun Feb 5 23:06:22 PST 2006
> >>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 "/".
More information about the talk