Regex for repeated character?

2005-06-16 Thread Leif K-Brooks
How do I make a regular expression which will match the same character repeated one or more times, instead of matching repetitions of any (possibly non-same) characters like ".+" does? In other words, I want a pattern like this: >>> re.findall(".+", "foo") # not what I want ['foo'] >>> re.finda

Re: Regex for repeated character?

2005-06-16 Thread Peter Otten
Leif K-Brooks wrote: > How do I make a regular expression which will match the same character > repeated one or more times, instead of matching repetitions of any > (possibly non-same) characters like ".+" does? In other words, I want a > pattern like this: > > >>> re.findall(".+", "foo") # not

Re: Regex for repeated character?

2005-06-16 Thread John Machin
Peter Otten wrote: > Leif K-Brooks wrote: > > >>How do I make a regular expression which will match the same character >>repeated one or more times, instead of matching repetitions of any >>(possibly non-same) characters like ".+" does? In other words, I want a >>pattern like this: >> >> >>> re.f

Re: Regex for repeated character?

2005-06-16 Thread Paul McGuire
A brute-force pyparsing approach - define an alternation of all possible Words made up of the same letter. Plus an alternate version that just picks out the repeats, and gives their location in the input string: from pyparsing import ZeroOrMore, MatchFirst, Word, alphas print "group string by cha

Re: Regex for repeated character?

2005-06-16 Thread Paul McGuire
One more bit, add this on to the code in the previous post: print "collapse repeated characters" repeats.setParseAction(lambda s,l,toks: toks[0][0]) print test,"->",repeats.transformString(test) Gives: collapse repeated characters foo ooobaaazZZ -> fo obazZ -- http://mail.python.org/mailman/li

Re: Regex for repeated character?

2005-06-17 Thread Chris Smith
> "Leif" == Leif K-Brooks <[EMAIL PROTECTED]> writes: Leif> How do I make a regular expression which will match the same Leif> character repeated one or more times, instead of matching Leif> repetitions of any (possibly non-same) characters like ".+" Leif> does? In other words,

Re: Regex for repeated character?

2005-06-17 Thread Doug Schwarz
In article <[EMAIL PROTECTED]>, Leif K-Brooks <[EMAIL PROTECTED]> wrote: > How do I make a regular expression which will match the same character > repeated one or more times, instead of matching repetitions of any > (possibly non-same) characters like ".+" does? In other words, I want a > patter

Re: Regex for repeated character?

2005-06-18 Thread John Machin
Doug Schwarz wrote: > In article <[EMAIL PROTECTED]>, > Leif K-Brooks <[EMAIL PROTECTED]> wrote: > > >>How do I make a regular expression which will match the same character >>repeated one or more times, instead of matching repetitions of any >>(possibly non-same) characters like ".+" does? In o

Re: Regex for repeated character?

2005-06-18 Thread Terry Hancock
On Saturday 18 June 2005 02:05 am, John Machin wrote: > Doug Schwarz wrote: > > In article <[EMAIL PROTECTED]>, > > Leif K-Brooks <[EMAIL PROTECTED]> wrote: > >>How do I make a regular expression which will match the same character > >>repeated one or more times, > > How's this? > > > > >>> [x[

Re: Regex for repeated character?

2005-06-18 Thread John Machin
Terry Hancock wrote: > On Saturday 18 June 2005 02:05 am, John Machin wrote: > >>Doug Schwarz wrote: >> >>>In article <[EMAIL PROTECTED]>, >>> Leif K-Brooks <[EMAIL PROTECTED]> wrote: >>> How do I make a regular expression which will match the same character repeated one or more times, >>>