Re: RegEx: find all occurances of a single character in a string

2004-12-15 Thread Fredrik Lundh
<[EMAIL PROTECTED]> 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: RegEx: find all occurances of a single character in a string

2004-12-15 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:05:38 +0100, Franz Steinhaeusler <[EMAIL PROTECTED]> wrote: >given a string: > >st="abcdatraataza" >^ ^ ^ ^ (these should be found) >I want to get the positions of all single 'a' characters. >(Without another 'a' neighbour) >[...] Thank you again, Pádraig and Stev

Re: RegEx: find all occurances of a single character in a string

2004-12-14 Thread P
[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: import re s='abcdatraataza' r=re.compile('(? Oops, tested this time: import re def index_letters(s,l): regexp='(? print index_letters('abcdatraataza','a') Just comparing Fredrik Lundh's method: r=re.compile("a+") [m.

Re: RegEx: find all occurances of a single character in a string

2004-12-14 Thread P
[EMAIL PROTECTED] wrote: import re s='abcdatraataza' r=re.compile('(? Oops, tested this time: import re def index_letters(s,l): regexp='(? print index_letters('abcdatraataza','a') -- Pádraig Brady - http://www.pixelbeat.org -- -- http://mail.python.org/mailman/listi

Re: RegEx: find all occurances of a single character in a string

2004-12-14 Thread Steven Bethard
Franz Steinhaeusler wrote: given a string: st="abcdatraataza" ^ ^ ^ ^ (these should be found) I want to get the positions of all single 'a' characters. (Without another 'a' neighbour) You could also try negative lookahead/lookbehind assertions: >>> st="abcdatraataza" >>> for m in re.findi

Re: RegEx: find all occurances of a single character in a string

2004-12-14 Thread P
Franz Steinhaeusler wrote: given a string: st="abcdatraataza" ^ ^ ^ ^ (these should be found) I want to get the positions of all single 'a' characters. (Without another 'a' neighbour) So I tried: r=re.compile('[^a]a([^a]') but this applies only for the a's, which has neighbours. So I

Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Fredrik Lundh
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 i

RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
given a string: st="abcdatraataza" ^ ^ ^ ^ (these should be found) I want to get the positions of all single 'a' characters. (Without another 'a' neighbour) So I tried: r=re.compile('[^a]a([^a]') but this applies only for the a's, which has neighbours. So I need also '^a' and 'a$'.

Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:19:35 +0100, "Fredrik Lundh" <[EMAIL PROTECTED]> 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

Re: RegEx: find all occurances of a single character in a string

2004-12-13 Thread Franz Steinhaeusler
On Tue, 14 Dec 2004 14:05:38 +0100, Franz Steinhaeusler <[EMAIL PROTECTED]> wrote: sorry >r=re.compile('[^a]a([^a]') r=re.compile('[^a]a[^a]') I meant. -- Franz Steinhaeusler -- http://mail.python.org/mailman/listinfo/python-list