当前位置: 代码迷 >> PHP >> 正则的有关问题,截取上面文章里的邮箱和Registrant:后的姓名,但是有好多不同情况,请教正则表达式该如何写
  详细解决方案

正则的有关问题,截取上面文章里的邮箱和Registrant:后的姓名,但是有好多不同情况,请教正则表达式该如何写

热度:5   发布时间:2016-04-28 23:57:02.0
正则的问题,截取下面文章里的邮箱和Registrant:后的姓名,但是有好多不同情况,请问正则表达式该怎么写?
情况1:
Registrant:
   
  jin mi
   
  jin mi 8
   
  shen zhen, guang dong 518000
   
  China
   
   
  Registered through: GoDaddy.com, LLC (http://www.godaddy.com)
   
  Domain Name: 760PK.COM
   
  Created on: 04-May-12
   
  Expires on: 04-May-13
   
  Last Updated on: 28-Jun-12
   
   
  Administrative Contact:
   
  mi, jin [email protected]
   
  jin mi 8
   
  shen zhen, guang dong 518000
   
  China
   
  +86.13510187966
   
   
  Technical Contact:
   
  mi, jin [email protected]
   
  jin mi 8
   
  shen zhen, guang dong 518000
   
  China
   
  +86.13510187966  
情况2:
Registrant:
   
  Domain Administrator
   
  Netease.com, Inc
   
  No.16, Ke Yun Rd Tianhe District
   
  GuangZhou GuangDong 510665
   
  CN
   
  [email protected] +86.2085106370 Fax: +86.2085106370
   
   
情况3:
Registrant:
   
  Zhiyong Duan
   
  Beijing Baidu Netcom Science Technology Co., Ltd.
   
  3F Baidu Campus No.10 Shangdi 10th Street Haidian District
   
  Beijing Beijing 100085
   
  CN
   
  [email protected] +86.1059924216 Fax: +86.1059927435
   
   


------解决方案--------------------
PHP code
//姓名preg_match_all('/Registrant:\s*(\w+\s+\w+)/s',$str,$name); print_r($name[1]);//邮箱preg_match_all('/\b[\w_]+@[\w\._]+/m',$str,$email); print_r($email);