Search code examples
regexqtqregularexpression

Regex matching repeating digits (3 or more) ignore whitespace


I have been investigating although I have not yet managed to figure out how to create a regex that will match digits only which repeat successively 3 or more times while ignoring whitespaces.

For example I have currently (\d)\1{3,} which matches

11112568856 etc 1111 2568 856 etc

although it fails when the repetition exists before and after a space

6111 1256 8856

What do I need to add to the regex in order to match this?


Solution

  • Use backreferences to match the same digit again:

    (\s?\d\s?)(\s?\1){2,}

    https://regex101.com/r/FNNS1z/3

    http://www.regular-expressions.info/backref.html