I want to find all consecutive, repeated character blocks in a string. For example, consider the following:
s = r'http://www.google.com/search=ooo-jjj'
What I want to find this: www, ooo and jjj.
I tried to do it like this:
m = re.search(r'(\w)\1\1', s)
But it doesn’t seem to work as I expect. Any ideas?
Also, how can I do it in Bash?
((\w)\2{2,})matches 3 or more consecutive characters:(\w)matches any alphanumeric character.((\w)\2)matches any alphanumeric character followed by the same character, since\2matches the contents of group number 2.Since I nested the parentheses, group number 2 refers to the character matched by
\w.Then putting it all together,
((\w)\2{2,})matches any alphanumeric character, followed by the same character repeated 2 or more additional times.In total, that means the regex require the character to be repeated 3 or more times.