Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
750 views
in Technique[技术] by (71.8m points)

regex - Regular Expression patterns for Tracking numbers

Does anybody know good place or patterns for checking which company tracking number is the given tracking number for a package. Idea is After scanning a barcode for a package check tracking number with patterns and show which company it was shipped by.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just thought I would post an update on this as I am working on this to match via jquery and automatically select the appropriate shipping carrier. I compiled a list of the matching regex for my project and I have tested a lot of tracking numbers across UPS FedEX and USPS.

If you come across something which doesn't match, please let me know here via comments and I will try to come up for that as well.

UPS:

/(1Z ?[0-9A-Z]{3} ?[0-9A-Z]{3} ?[0-9A-Z]{2} ?[0-9A-Z]{4} ?[0-9A-Z]{3} ?[0-9A-Z]|[dT]ddd ?dddd ?ddd)/

FedEX: (3 Different Ones)

/(96d{20})|(d{15})|(d{12})/
/((98ddddd?dddd|98dd) ?dddd ?dddd( ?ddd)?)/
/^[0-9]{15}$/

USPS: (4 Different Ones)

/(d{30})|(91d+)|(d{20})/
/^ED{1}d{9}D{2}$|^9d{15,21}$/
/^91[0-9]+$/
/^[A-Za-z]{2}[0-9]+US$/

Please note that I did not come up with these myself. I simply searched around and compiled the list from different sources, including some which may have been mentioned here.

Thanks

Edit: Fixed missing end delimiter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...