The problem is you are "anchoring" the regex by using the beginning of input (^
) and end of input ($
) metacharacters.
What you are saying, in essense, is match nothing BUT a zip code (with no surrounding text). Just remove the anchoring characters, and your solution will work:
\d{5}(?:[-\s]\d{4})?