Home > Computing, Programming, php > REGEX For common courier tracking numbers

REGEX For common courier tracking numbers

I was on the hunt not only to find the different variations each courier had for their tracking numbers but also a regex to match. Most of the google fu I found was outdated. Fedex “recently” (months? years? days?) changed from a 12 digit to 15 digit system. And NO, tracking numbers are not totally random. There is usually a space separation on the printed labels you see. Each of the spaced out subsets have a meaning to the courier as well as a checksum. Checksum being, a pre selected sequence of particular number positions added together then divided by a pre selected number. That you can search up yourself if you like. I didn’t find all too much on that matter either.

I am not very good with regex so if there are any suggestions by l33t coderz, they are more than welcome. On with the codes:

[ UPS ]
9 digits, or 1Z+whatever digits
The quick brown fox 1Z9999W99999999999 jumps over the lazy dog.
$ups = '/(\b\d{9}\b)|(\b1Z\d+\b)/';

[ Fedex ]
12 digits, 15 digits, or '96'+ 20 digits
The quick brown fox 999999999999 jumps over the lazy dog.
$fedex = '/(\b96\d{20}\b)|(\b\d{15}\b)|(\b\d{12}\b)/';

[ USPS ]
30 digits, '91'+20 digits, 20 digits (untested)
$usps = '/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)/';

I did get the common characters per courier from Packagetrackr. I don’t know how much of it is accurate, but from what I could tell from my experience with FedEx and UPS it seemed to be in line. I was unable to find an all inclusive source.

Categories: Computing, Programming, php Tags:
  1. July 6th, 2015 at 03:53 | #1

    Thanks for sharing these info with us! this is a great site. I really like it. Thank you for the site. May God bless you in all your works

Comment pages
1 2 322
  1. No trackbacks yet.