re module non-greedy matches broken

lothar lothar at ultimathule.nul
Tue Apr 5 12:10:12 EDT 2005


a non-greedy match - as implicitly defined in the documentation - is a match
in which there is no proper substring in the return which could also match
the regex.

you are skirting the issue as to why a matcher should not be able to return
a non-greedy match.

there is no theoretical reason why it can not be done.



"André Malo" <auch-ich-m at g-kein-spam.com> wrote in message
news:d2tc04$84s$1 at news.web.de...
> * "lothar" <lothar at ultimathule.nul> wrote:
>
> > no - in the non-greedy regex
> >   <1st-pat><not-1st-pat>*?<follow-pat>
> >
> > <1st-pat>, <not-1st-pat> and <follow-pat> are arbitrarily complex
patterns.
>
> The "not" is the problem. Regex patterns are expressed positive by
> definition (meaning, you can say, what you expect, but not what you
> don't expect). In other words, regexps were invented to define (uh...
regular)
> sets, nothing more (especially you can't define "non-sets"). So the usual
> way is to define the set you've called '<not-1st-pat>*?' and describe
> it as regex. Modern regular expression engines (which are no longer
regular
> by the way ;-) allow shortcuts like negative lookahead assertions and the
> like.
>
> I want to make clear, that it isn't, that nobody _wants_ to give an advice
> how to express your pattern in general. The point is, that there's no
> real syntax for it. It depends on how your <1st-pat> and <follow-pat> look
> like. Chances are, that's even not expressable in one regex (depends on
> the complexity and kind of the set they define).
> Each pattern you write is special to the particular use case.








More information about the Python-list mailing list