php regex, extract like phone number regex from html documents

后端 未结 5 2153
渐次进展
渐次进展 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:19

    Here's a good starting point:

     
    

    Note the non-capturing subpatterns (which look like (?:stuff)). That makes formatting easy:

    
    

    And some example results for you:

    520-555-5542 :: MATCH 
    520.555.5542 :: MATCH 
    5205555542 :: MATCH 
    520 555 5542 :: MATCH 
    520) 555-5542 :: FAIL 
    (520 555-5542 :: FAIL 
    (520)555-5542 :: MATCH 
    (520) 555-5542 :: MATCH 
    (520) 555 5542 :: MATCH 
    520-555.5542 :: MATCH 
    520 555-0555 :: MATCH 
    (520)5555542 :: MATCH 
    520.555-4523 :: MATCH 
    19991114444 :: FAIL 
    19995554444 :: MATCH 
    514 555 1231 :: MATCH 
    1 555 555 5555 :: MATCH 
    1.555.555.5555 :: MATCH 
    1-555-555-5555 :: MATCH 
    520-555-5542 ext.123 :: MATCH 
    520.555.5542 EXT 123 :: MATCH 
    5205555542 Ext. 7712 :: MATCH 
    520 555 5542 ext 5 :: MATCH 
    520) 555-5542 :: FAIL 
    (520 555-5542 :: FAIL 
    (520)555-5542 ext .4 :: FAIL 
    (512) 555-1234 ext. 123 :: MATCH 
    1(555)555-5555 :: MATCH
    

    You'll probably get a lot of false positives if you allow spaces and dashes like you're suggesting.

提交回复
热议问题