split encloser

Alex Martelli aleax at aleax.it
Sat Apr 12 14:53:55 EDT 2003


Chris wrote:

> looked at stuff about Python regular expressions and there is
> something called finditer and findall that might be useful for parsing
> a string, but can't seem to find any documentation on them.

http://www.python.org/doc/current/lib/node99.html

Actually I find sub (passing a function as "repl") more useful than 
findall (finditer is roughly as useful as sub), but sub's documented 
on the same URL, anyway.  Not everybody likes working "by callbacks",
which is what sub + a function lets you do -- findall and finditer
are more direct, and finditer is basically just as powerful as sub,
as it returns match-objects one after the other, while findall just
returns a list of substrings, not quite as powerful -- though surely,
some of the time (when that's all you need), it may be even handier.


Alex





More information about the Python-list mailing list