php正则表达式来过滤数据

时间:2013-03-18 16:08:30

标签: php regex

我只是陷入了使用php正则表达式来过滤数据。我想使用正则表达式检测“结果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
任何想法?

3 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

您可以使用此正则表达式

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

删除Results 1 - 20 of 60

答案 2 :(得分: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