I define "Repeating words" as this regex (use PyPI package, not builtin re
):
import regex
repeating = regex.compile(r"(\w+)(?:\W+\1){4,}")
It will catch words that are repeated 5 times or more, for example
Answer Answer Answer Answer Answer Answer Answer Answer Answer Answer
However, if the word varies by capitalization, the regex fails:
Answer answer Answer answer Answer answer Answer answer Answer answer
How can I modify the regex so it catches "repeating words" that varies in capitalization? I want it to match
answer ANSWER ansWER Answer anSwer AnSwEr
Note: str.lower()
is not an option because I need the exact capitalization of the captured group.