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
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
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
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
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
> "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,
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
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
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[
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,
>>>
10 matches
Mail list logo