help with simple regular expression grouping with re

Aahz Maruch aahz at netcom.com
Mon May 10 11:19:55 EDT 1999


In article <wkbtftdo1r.fsf at turangalila.harmonixmusic.com>,
Dan Schmidt  <dfan at harmonixmusic.com> wrote:
>
>  So "(.*?)" and "([^"]*)" both solve the problem; you don't need to
>  disallow quotes _and_ match non-greedily.

In general, though, character classes are much faster than *any* form of
"." that might involve backtracking.  I believe this is still true even
with "non-greedy" specified.  People who use regexes heavily tend to
automatically try to phrase things via character classes when possible.
What I don't know is whether using non-greedy with a character class
adds anything.
-- 
                      --- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6       <*>      http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

"In the end, outside of spy agencies, people are far too trusting and
willing to help."  -- Ira Winkler




More information about the Python-list mailing list