php regex, extract like phone number regex from html documents

后端 未结 5 2154
渐次进展
渐次进展 2021-01-16 09:33

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         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-16 10:02

    Consider other delimiters besides hyphens, not to mention parentheses.

    (?:1\s*?[-.]?\s*)?(?:\(\s*d{3}\s*\)|d{3})\s*?[-.]?\s*\d{3}\s*?[-.]?\s*\d{4}\b
    

    Okay, maybe that's more comprehensive than you need, but really this can get as complicated as you like. You can expand it to look for international phone numbers, extensions, and so forth, but that might not be worth it for you.

提交回复
热议问题