Here's a piece of Python code that tells me if any character in a string occurs four times in a row:
str = "hello!!!!"
for i in range(0, len(str)-3):
if str[i] == str[i+1] == str[i+2] == str[i+3]:
print("yes")
What's a more Pythonic way of writing this, preferably with a regular expression?
I'm aware of this similar question but it asks about a specific character, not any character.
Number of the same characters in a row - python
@JBernardo has an answer with regular expressions but it wants a particular character to match against.
I'm using Python 3, if it matters in your answer.