跟踪数字的正则表达式模式 [英] Regular Expression patterns for Tracking numbers

查看:133
本文介绍了跟踪数字的正则表达式模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道检查哪个公司跟踪号是包裹给定跟踪号的好地方或模式.想法是在扫描条形码以获得包裹后,检查跟踪码和图案,并显示其发运的公司.

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.

推荐答案

我只是想发布此更新,因为我正在通过jquery进行匹配并自动选择合适的运输公司.我为我的项目整理了一个匹配的正则表达式列表,并且在UPS FedEX和USPS上测试了很多跟踪号.

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:

/\b(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]\d\d\d ?\d\d\d\d ?\d\d\d)\b/

FedEX:(3个不同的版本)

FedEX: (3 Different Ones)

/(\b96\d{20}\b)|(\b\d{15}\b)|(\b\d{12}\b)/
/\b((98\d\d\d\d\d?\d\d\d\d|98\d\d) ?\d\d\d\d ?\d\d\d\d( ?\d\d\d)?)\b/
/^[0-9]{15}$/

USPS:(4个不同的)

USPS: (4 Different Ones)

/(\b\d{30}\b)|(\b91\d+\b)|(\b\d{20}\b)/
/^E\D{1}\d{9}\D{2}$|^9\d{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.

谢谢

修复了缺少的结束定界符.

Fixed missing end delimiter.

这篇关于跟踪数字的正则表达式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆