Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有大约 10,000 个字符串要从中提取电话号码,其中一些电话号码格式如下:
08978803929 085282486601 081284671191 +6285722345678
模式如下,要么是08开头的连续数字串,要么是11位,要么是12位。它前面也可以有+62的区号。如何在 PHP 中使用正则表达式提取所有这些字符串?
为了使它更简单,我想检测以 08 或 +62 或仅 62 开头的字符串
您可以使用此正则表达式:
^(\+?62|08)[0-9]{9,11}$
解释:
- ^ and $ - Line start and Line end - (\+?62|08) - starting with 62 OR +61 OR 08 [0-9]{9,11} - match 9 to 11 digits