如何使用大量正则表达式删除细节?
例如
删除前:
Live => [US] United States | example1@yahoo.com | Checked on 5:59 pm - May 17, 2015
Live => [US] United States | example2@yahoo.com | Checked on 5:59 pm - May 17, 2015
Live => [US] United States | example3@yahoo.com | Checked on 5:59 pm - May 17, 2015
Live => [US] United States | example4@yahoo.com | Checked on 5:59 pm - May 17, 2015
Live => [US] United States | example5@yahoo.com | Checked on 5:59 pm - May 17, 2015
删除后:
example1@yahoo.com
example2@yahoo.com
example3@yahoo.com
example4@yahoo.com
example5@yahoo.com
请在regex101上使用demo演示:)
之前谢谢答案 0 :(得分:0)
答案 1 :(得分:0)
使用下面的正则表达式,然后用空字符串替换匹配。
^[^|]*\|\s*|\s*\|.*
在php中,您需要使用preg_replace
函数。
$re = "/^[^|]*\\|\\s*|\\s*\\|.*/m";
$str = "Live => [US] United States | example1@yahoo.com | Checked on 5:59 pm - May 17, 2015 \nLive => [US] United States | example2@yahoo.com | Checked on 5:59 pm - May 17, 2015 \nLive => [US] United States | example3@yahoo.com | Checked on 5:59 pm - May 17, 2015 \nLive => [US] United States | example4@yahoo.com | Checked on 5:59 pm - May 17, 2015 \nLive => [US] United States | example5@yahoo.com | Checked on 5:59 pm - May 17, 2015 ";
$subst = "";
$result = preg_replace($re, $subst, $str);
echo $result;