Q for regexp experts

Fredrik Lundh fredrik at effbot.org
Fri Dec 8 10:31:56 EST 2000


Harald Kirsch wrote:
> Even with perl-compatible regular expressions it seems to be
> impossible to specify a pattern which matches
>
>    `the longest substring not containing separator' SEP
>
> Put another way, from a given starting point, the pattern shall
> match everything until just before the next occurence of SEP.

why not just use non-greedy repeat and a group?

    m = re.match("(.*?)SEP", text)
    print m.group(1)

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list