When Good Regular Expressions Go Bad

Douglas Alan nessus at mit.edu
Tue Sep 28 21:38:18 EDT 1999


I'm probably just out of luck (i.e., I can't find any mention of it in
the FM), but just in case, I'll ask anyway.  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.

Now, perhaps what I am asking for doesn't make much sense for regular
expressions that involve backtracking, but in this case some response
could still be provided -- perhaps, for instance, the longest string
that was partially matched.  Or, a bit less usefully, just the last
location where it got stuck.

|>oug




More information about the Python-list mailing list