MartijnK MartijnK - 4 months ago 9
Javascript Question

Regex pattern to find a multiple non-digit characters recurring

I'm trying to get regex to find matches where in a string of numbers there are more than one instance of a non-digit chracter following each other.

Ie.

0-31-334455(555)
would not be a match, but
0--31-334455()555
would be (twice).

Thus far I have mangled this together:
([\(\)\-\+\s])\1{1,}
, which checks for multiple instances of
() -+
following each other, but it misses
()
for instance.

([()\\-+ ])\\1
also finds two (or more) of the same character in a row, but it misses
()
.

I'm assuming that something like a not-digit (
\d
) would be easier than defining every character you don't want, but I don't see how to include that.

Answer

There is a not-digit character class which is \D, so just try \D\D
See this regex101 for a quick example