I would like to check a string for repeated characters in a row until the next space.
For example:
The following string has 4 O's in a row and I would like to detect that somehow.
myString = 'I contain foooour O's in a row without any space'
It doesnt matter what character it is as long as It's being repeated 4 times in a row without any space.
How can I achieve this and what are my options?
One general solution might be to use re.findall with the pattern ((\S)\2{3,}):
myString = "I contain foooour O's in a row without any space"
matches = re.findall(r'((\S)\2{3,})', myString)
print(matches[0][0])
This prints:
oooo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With