preg_match模式下一行第二个单词

时间:2012-05-31 21:50:56

标签: php preg-match preg-match-all

我有这个主题的preg_match模式`/admin[^:]*:\s*(.* )/i(作为样本)

txt stuff
Administrative Contact:
Brown, John support@xxxxxxx.com
txt stuff

拔出“Brown,John support@xxxxxxx.com”,但我需要搜索和打印“Brown,John”(名称),而不是整行(一切都是名称而不是电子邮件)。 这是一段大文本,唯一的静态字符串是“Administrative Contact:”。

由于

1 个答案:

答案 0 :(得分:0)

http://ideone.com/u0UgL

$str = 'txt stuff
Administrative Contact:
Brown, John support@xxxxxxx.com
txt stuff';

preg_match('~admin[^:]*:\s*(.*)\s+\S+@~i', $str, $matches);
var_dump($matches[1]); // string(11) "Brown, John"
相关问题