通过正则表达式从列表中获取域列表

时间:2013-06-22 16:46:05

标签: php regex

我有域名列表和其他信息

domain1.com;somedata1;somedata2;2012-03-02;somedata3;somedata4;somedata5
domain2.com;somedata5;somedata8;2013-06-18;somedata4;somedata2;somedata1
domain3.org;somedata9;somedata2;2012-03-02;somedata3;somedata4;somedata5
domain4.com;somedata1;somedata2;2015-04-18;somedata3;somedata4;somedata5
domain5.com;somedata1;somedata2;2012-03-02;somedata3;somedata4;somedata5
domain6.biz;somedata5;somedata8;2013-06-18;somedata4;somedata2;somedata1
domain7.org;somedata9;somedata2;2012-03-02;somedata3;somedata4;somedata5
domain8.com;somedata1;somedata2;2015-04-18;somedata3;somedata4;somedata5

我需要获取.com域名列表,其中日期为2012-03-02

我需要使用类似的东西:

preg_match('(.*?.com)   ????  /i', $data, $matches);

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

preg_match_all('~^\S+?.com(?=;[^;]*+;[^;]*+;2012-03-02;)~mi', $data, $matches);

答案 1 :(得分:1)

  preg_match_all( '/([A-Z0-9][A-Z0-9_-]*(?:\.com*)+):?(\d+)?\/?(.+?)(2012\-03\-02)/i', $data, $matches );
  print_r( $matches[1] );