The first expression matches because it finds "12345". You're asking it to find at least one numeric digit but up to five.
If you used preg_match_all() instead, it would make a match on "12345" and then again on "6789".
If you used '/\d{1,5}?/' expression instead, then that would match the least number of digits each time. The question mark makes it lazy (match as few as possible up to 1 in this instance). Without the question mark it's greedy (match as many as possible up to 5 in this instance).
FYI: Link # 9 under "Regex/PCRE:" in my signature is to a nifty program well worth the $30 price tag.