Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
(?<d> [0-9] [-_ –.]* ){4} # subpattern definition (?= \g<d>{4} (?: \g<d> (?: \g<d>{3} )? )? # allowed digit sequences (?: \g<d>+ (*SKIP) (*F) )? # skip the substring if digits remain ) \g<d>* (?= \g<d>{4} ) # backtrack until there're 4 digits at the end
/
gux
Input 1
New
valid: 12345678 123456789 123456789012 123-456789 123 45 6789 123 – 45 – 6789 invalid: 1234567 1234567890 12345678901 1234567890123