-1

我的表格列信息中有以下数据

array( 'Email: Customer One <customer1@yahoo.com>. By employee: james@company.com.',
    'By employee: james@company.com. Department Head: Nickolas Jim.',
    'Email: Customer One <customer2@yahoo.com>. Status: currently employees.',
    'Email: Customer One <customer3@yahoo.com>. By employee: Mirza@company.com.'
)

等等等等

我需要从数组中获取“按员工”。换句话说,我需要正则表达式解决方案

教育署。我只需要 By 员工(如果存在)..没有别的所以在上面的例子中我会有

By employee: james@company.com
By employee: james@company.com
By employee: Mirza@company.com
4

1 回答 1

1

我在 php 5.4.5 中测试了以下示例代码:

    <?php
$foo = array( 'Email: Customer One <customer1@yahoo.com>. By employee: james@company.com.',
              'By employee: james@company.com. Department Head: Nickolas Jim.',
              'Email: Customer One <customer2@yahoo.com>. Status: currently employees.',
              'Email: Customer One <customer3@yahoo.com>. By employee: Mirza@company.com.'
            );

for($i = 0; $i < count($foo); ++$i){
    if(0 >= preg_match('/\bBy employee: ([-\w._]+@[-\w]+(?:\.[-\w]+)*\.\w{2,4})\b/', $foo[$i], $matches))
        continue;  

    echo $matches[0] . "\n";
    echo $matches[1] . "\n";
    echo "\n";  
}            

?>

输出:

        By employee: james@company.com
james@company.com

By employee: james@company.com
james@company.com

By employee: Mirza@company.com
Mirza@company.com
于 2012-08-02T01:23:23.017 回答