I am using python 2.6 and trying to find a bunch of duplicate characters in a string, say a bunch of n , for example. nnnnnnnABCnnnnnnnnnDEF . Anywhere in a string, n can be a variable.
If I create a regex like this:
re.findall(r'^(((?i)n)\2{2,})', s) ,
I can find cases of case insensitivity n only at the beginning of the line, which is good. If I do it like this:
re.findall(r'(((?i)n)\2{2,}$)', s) ,
I can only find them at the end of the sequence. But what about in the middle?
At first I thought of using
re.findall(r'(((?i)n)\2{2,})', s) and the two previous regular expressions (-ices?) To check the length of the returned list and the presence of
n either in beginning or at the end of the line and do logical tests, but it became very ugly, if-still mess very quickly.
Then I tried re.findall(r'(?!^)(((?i)n)\2{2,})', s) , which seems to exclude the beginning just fine, but (?!$) or (?!\z) at the end of the regular expression excludes only the last n in ABCnnnn . Finally, I tried re.findall(r'(?!^)(((?i)n)\2{2,})\w+', s) , which seems to work sometimes, but I get weird results in others. It seems to me that I need a look or a look, but I can’t circle my head around me.