I’m looking for a simple regular expression to match the same character being repeated more than 10 or so times. So for example, if I have a document littered with horizontal lines:
=================================================
It will match the line of = characters because it is repeated more than 10 times. Note that I’d like this to work for any character.
The regex you need is
/(.)\1{9,}/.Test:
Here the
\1is called a backreference. It references what is captured by the dot.between the brackets(.)and then the{9,}asks for nine or more of the same character. Thus this matches ten or more of any single character.Although the above test script is in Perl, this is very standard regex syntax and should work in any language. In some variants you might need to use more backslashes, e.g. Emacs would make you write
\(.\)\1\{9,\}here.If a whole string should consist of 10 or more identical characters, add anchors around the pattern: