regex - Remove strings with repeating characters [Python] -
i need determine if string composed of repeating character, example eeeee, 55555, or !!!.
i know regex 'e{1,15}' can match eeeee can't match 555. tried [a-z0-9]{1-15} matches strings don't need hello.
the solution doesn't have regex. can't think of other way this.
a string consists of single repeating character if , if characters in same. can test constructing set out of string: set('55555').
all characters same if , if set has size 1:
>>> len(set('55555')) == 1 true >>> len(set('hello')) == 1 false >>> len(set('')) == 1 false if want allow empty string (set size 0), use <= 1 instead of == 1.
Comments
Post a Comment