Regex for repeated character?

John Machin sjmachin at lexicon.net
Sat Jun 18 20:16:50 EDT 2005


Terry Hancock wrote:
> On Saturday 18 June 2005 02:05 am, John Machin wrote:
> 
>>Doug Schwarz wrote:
>>
>>>In article <5J9se.136$Q75.39412 at newshog.newsread.com>,
>>> Leif K-Brooks <eurleif at ecritters.biz> wrote:
>>>
>>>>How do I make a regular expression which will match the same character
>>>>repeated one or more times,
>>>
>>>How's this?
>>>
>>>  >>> [x[0] for x in re.findall(r'((.)\2*)', 'abbcccddddcccbba')]
>>>  ['a', 'bb', 'ccc', 'dddd', 'ccc', 'bb', 'a']
>>
>>I think it's fantastic, but I'd be bound to say that given that it's the 
>>same as what I posted almost two days ago :-)
> 
> 
> Guess there's only one obvious way to do it, then. ;-)
> 

Yep ... but probably a zillion ways in
re.compile(r"perl", re.I).match(other_languages)




More information about the Python-list mailing list