ungreedy regular expressions

Michael Hudson mwh21 at cam.ac.uk
Wed Apr 26 08:01:03 EDT 2000


ckotso at cs.ntua.gr (Constantinos A. Kotsokalis) writes:

> I recently added two lines of code to the python distribution, in order
> to support ungreedy regular expressions (which are supported by pcre
> but I could find no way to use them in python code). If there is some
> way already that I am not aware of, please e-mail me :-) If you are
> interested in having it available, edit Modules/pcremodule.c and add
> the line:

Aren't the *?,+? patterns "ungreedy"?

>>> re.match("(a+)(.*)","aaabbb").groups()
('aaa', 'bbb')
>>> re.match("(a+?)(.*)","aaabbb").groups()
('a', 'aabbb')

HTH,
Michael

-- 
  it's not that perl programmers are idiots, it's that the language
  rewards idiotic behavior in a  way that no other language or tool 
  has ever done                        -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list