RegEx: find all occurances of a single character in a string
Fredrik Lundh
fredrik at pythonware.com
Wed Dec 15 06:06:48 EST 2004
<P at draigBrady.com> wrote:
> r=re.compile("a+")
> [m.start() for m in r.finditer(s) if len(m.group()) == 1]
>
< Mine runs 100K iterations of 'abcdatraataza','a' in 1.4s
> whereas Fredrik's does the same in 1.9s
sure, but how long did it take you to come up with a working RE? and how
many casual RE users will understand what the heck that RE is doing?
(insert obligatory remark about premature optimization, etc).
</F>
More information about the Python-list
mailing list