This has already been shared in a comment, but just to provide a complete-ish answer…
You have these tools at your disposal:
x
matchesx
exactly oncex{a,b}
matchesx
betweena
andb
timesx{a,}
matchesx
at leasta
timesx{,b}
matchesx
up to (a maximum of)b
timesx*
matchesx
zero or more times (same asx{0,}
)x+
matchesx
one or more times (same asx{1,}
)x?
matchesx
zero or one time (same asx{0,1}
)
So you want to use that last one, since it’s exactly what you’re looking for (zero or one time).
/\d{3}[^0-9a-zA-Z]?\d{2}[^0-9a-zA-Z]?\d{4}/