When Good Regular Expressions Go Bad
Tim Peters
tim_one at email.msn.com
Wed Sep 29 02:55:19 EDT 1999
[Douglas Alan]
> ...
> 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!) For instance, let's say that I have
> the regular expression "^foo.bar", and I try to match it on the
> string "fooxbaz". It might be useful to be able to find out that
> the regular expression was able to get all the way through "fooxb"
> before giving up the ghost.
I believe this would be easy to add to any regexp engine I've ever seen, and
also believe I've never seen one that keeps track of it. I confess I'm at a
loss to think of a compelling use for it, though. In this particular case,
you could track it yourself in a Python/Perl-style "left to right" engine
via
^(foo.bar|foo.ba|foo.b|foo.|foo|fo|f)
or, more confusingly,
^f(o(o(.(b(ar?)?)?)?)?)?
If you're motivated enough to endure that, you really may have a good use
for it <wink>.
then-you-just-need-to-convince-others-they-do-too-ly y'rs - tim
More information about the Python-list
mailing list