0

I'm using the solution obtained from this question Regular expression to match any character being repeated more than 10 times

The regex you need is /(.)\1{9,}/.

https://regex101.com/ is recognizing it, grep recognizes it, but python does not.

Ultimately I want to replace the match with a single space, for example:

>> text = 'this is text???????????????'
>> pattern = re.compile(r'/(.)\1{5,}/')
>> re.sub(pattern,'\s',text)
'this is text '

However, search, findall, even match do not recognize the pattern, any idea as to why?

Community
  • 1
  • 1
Leb
  • 15,483
  • 10
  • 56
  • 75

1 Answers1

3
re.sub(r'(.)\1{9,}', ' ',text)

The slashes are not part of the regex, they are a syntactic construct by which some languages form regex literals (and in case of PHP's preg module, an oddity).

With your regexp, you would have matched this is text/?????????????/, and transformed it into this is text\s (note that \s has no meaning in the replacement string).

Amadan
  • 191,408
  • 23
  • 240
  • 301