php正则表达式,从html文档中提取电话号码正则表达式 [英] php regex, extract like phone number regex from html documents

查看:69
本文介绍了php正则表达式,从html文档中提取电话号码正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从不同的 html 页面中提取特定信息.基本上,信息是一个 10 位数字,可能有不同的形式,例如:

<前>000-000-0000000 - 000 - 00000000000000

<前>请注意,000 - 000 - 0000000 不是有效的电话号码,因此如果该号码包含任何其他数字,则不应提取该号码

如果您能帮助我创建适用于所有 3 种情况的完美正则表达式,我将不胜感激.到目前为止,我只能让它对最后一个(最简单的)起作用.

解决方案

这将匹配您列出的所有三个示例.

(\d{3}\s*-?\s*\d{3}\s*-?\s*\d{4})

I'm trying to extract a specific information from different html pages. Basically the information is a 10 digits number which may have different forms such :

000-000-0000
000 - 000 - 0000
0000000000

please note that 000 - 000 - 0000000 is not a valid phone number so it should not extract the number if it contains any additional digits

I would appreciate any help to create the perfect regex working on all the 3 situations . So far I could make it work only for the last one (the simplest one ).

解决方案

This will match on all three examples you listed.

(\d{3}\s*-?\s*\d{3}\s*-?\s*\d{4})

这篇关于php正则表达式,从html文档中提取电话号码正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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