我只是被 php 正则表达式卡住来过滤数据。我想使用正则表达式检测'Results 1 - 20 of 60',然后从中删除数据$content
$content="We have Results 1 - 20 of 60 some blah blah blah";
$content = preg_replace("/regular-expression/", " ", $content);
这里的预期输出是:有We have some blah blah blah
什么想法吗?
很快,这里有一个解决方案
$content="We have Results 1 - 20 of 60 some blah blah blah";
$content = preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $content);
你可以使用这个正则表达式
$content = preg_replace("/\s*results\s+\d+\s+-\s+\d+\s+of\s+\d+\s*/i", " ", $content);
删除Results 1 - 20 of 60
.
您可以通过
<?php
$str="We have Results 1 - 20 of 60 some blah blah blah";
echo preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $str);
?>
输出
We have some blah blah blah