RegEx: find all occurances of a single character in a string
Franz Steinhaeusler
franz.steinhaeusler at utanet.at
Tue Dec 14 08:35:47 EST 2004
On Tue, 14 Dec 2004 14:19:35 +0100, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:
>Franz Steinhaeusler wrote:
>> given a string:
>>
>> st="abcdatraataza"
>> ^ ^ ^ ^ (these should be found)
>> I want to get the positions of all single 'a' characters.
>
>for m in re.finditer("a+", st):
> if len(m.group()) == 1:
> print m.start()
>
>or, perhaps:
>
>indexes = [m.start() for m in re.finditer("a+", st) if len(m.group()) == 1]
>
></F>
>
>
Great!
thank you for your quick and helpful reply!
--
Franz Steinhaeusler
More information about the Python-list
mailing list