3

我只是被 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
什么想法吗?

4

3 回答 3

3

很快,这里有一个解决方案

$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);
于 2013-03-18T16:10:32.443 回答
0

你可以使用这个正则表达式

 $content = preg_replace("/\s*results\s+\d+\s+-\s+\d+\s+of\s+\d+\s*/i", " ", $content);

删除Results 1 - 20 of 60.

于 2013-03-18T16:11:43.500 回答
0

您可以通过

<?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
于 2013-03-18T16:13:52.687 回答