我在哪里可以获得用于识别街道地址、邮政编码、州、电话号码、电子邮件等的正则表达式或库包?

发布于 2024-08-04 12:21:26 字数 70 浏览 4 评论 0原文

我有一堆未格式化的文档...

我需要正则表达式来捕获街道地址、邮政编码、州、电话号码、电子邮件等常见格式...

i have bunch of unformatted docs....

i need regex to capture street address, postal code, state, phone numbers, emails, such common formats...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-08-11 12:21:26

此网站提供了一个可搜索的正则表达式库: 以及这个 正则表达式食谱 包含数百个正则表达式匹配模式的示例

This site offers a searchable library of regexs: and this regular expression cookbook contains hundreds of examples of regex matching patterns

双手揣兜 2024-08-11 12:21:26

对于街道地址以及某种程度上的邮政编码,正则表达式只能做到这一点。事实上,尝试对街道进行正则表达式基本上是不可能的,因为街道地址的格式多种多样——即使是在美国境内也是如此。

对于严格格式的美国邮政编码来说效果相当好的正则表达式是: ^\d{5}([-+]?\d{4})?$

在美国,邮政编码的通常格式如下:

  • 12345
  • 123456789
  • 12345-6789
  • 12345+6789 12345-67ND(是的,您没看错,有时最后两个可以是“ND”)

您将遇到的另一个问题是当零前缀邮政编码(例如来自新英格兰的邮政编码)具有通过 Excel 运行,它删除了前导零,留下一个四位数。这就是为什么仅靠正则表达式无法 100% 完成工作,即使对于像美国邮政编码这样“简单”的东西也是如此。

根据业务需求,您需要研究地址验证解决方案。任何称职的在线提供商都可以标准化、验证地址,告诉您地址是否真实,并有助于减少欺诈和退货运费等。

为了充分披露,我是 SmartyStreets 的创始人。我们提供在线地址验证服务,可以清理、标准化和验证地址。如果您有任何疑问,我们非常欢迎您亲自与我联系。

In the case of street addresses and to a certain extent, postal codes, regexs can only go so far. As a matter of fact, trying to regex a street is essentially impossible because of the huge variety of formats for a street address--even from within the United States.

A regex that has worked rather well for strictly formatted US-based postal codes is: ^\d{5}([-+]?\d{4})?$

In the US, ZIP Codes are typically formatted as follows:

  • 12345
  • 123456789
  • 12345-6789
  • 12345+6789 12345-67ND (yes, you read that right, sometimes the last two can be "ND")

The other issue that you'll have is when a zero-prefixed ZIP such as one from New England has been run through Excel and it has removed the leading zero, leaving a four-digit number. This is why a regex alone can't get the job done 100% even for something as "simple" as a US-based ZIP Code.

Depending upon the business needs, you'll want to investigate an address verification solution. Any online provider worth their salt can standardize and verify and address which tells you if the address is real and can help reduce fraud and return shipping, etc.

In the interest of full disclosure, I'm the founder of SmartyStreets. We have an online address verification service which cleans, standardizes, and validates addresses. You're more than welcome to contact me personally for any questions you have.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文