When Good Regular Expressions Go Bad
Douglas Alan
nessus at mit.edu
Wed Sep 29 12:59:53 EDT 1999
"Tim Peters" <tim_one at email.msn.com> writes:
> > It seems to me that even when a regular expression fails to match a
> > string, you might want to know just how far it was able to get before
> > getting stuck. (And indeed I do!)
> I confess I'm at a loss to think of a compelling use for it, though.
Here's what I'd like to use it for: I'm writing a function that does a
directory walk. The client of the function can provide a regular
expression, indicating the pathnames on which they would like to
match. I would like to optimize the function by pruning any
directories for which the contents could not possibly match the
regular expression.
Sure, the function could instead accept a filtering function as an
argument, instead of the regular expression, and the client could then
provide their own pruning, or I could just require that the regular
expression also match directories to be descended into. But these
interfaces are not nearly so nice.
|>oug
More information about the Python-list
mailing list