Find first matching substring

John Machin sjmachin at lexicon.net
Fri Jul 17 21:54:11 EDT 2009


On Jul 18, 2:11 am, Eloff <dan.el... at gmail.com> wrote:
> Almost every time I've had to do parsing of text over the last 5 years
> I've needed this function:
[snip]
> It finds the first matching substring in the target string, if there
> is more than one match, it returns the position of the match that
> occurs at the lowest index in the string.

Alternatives:
(1) re.search(r"sub0|sub1|...", ...)
(2) google "Aho Corasick Python" (one result should be a thread in
this newsgroup within the last week)



More information about the Python-list mailing list