代码之家  ›  专栏  ›  技术社区  ›  Incognito

preg\ U完全相反

  •  0
  • Incognito  · 技术社区  · 14 年前

    我想从这一行中得到相反的匹配:

    $input = "21.asdf*234true;asdf0--11"
    $_BOOL_ ="/(true|false)/i";
    $output = preg_replace($_BOOL_, '', $input);
    //Result: "21.asdf*234;asdf0--11"
    //Desired result: "true"
    

    PHP5.3中的哪一个是

    $output = preg_filter($_BOOL_, '', $input);

    但我在5.2,不知道怎么才能得到我想要的。。。建议(除了在ubuntu上编译5.3)?

    2 回复  |  直到 11 年前
        1
  •  1
  •   Chris Sobolewski    14 年前

    你的例子还是有点模糊。

    如果你要找的是这种情况 preg_match()

    如果您希望在字符串包含true时返回“true”,在字符串包含false时返回“false”,我认为您可能需要使用一系列函数,例如preg\u match()或strpos()来分别匹配每个条件。

        2
  •  0
  •   Alan Moore Chris Ballance    14 年前

    怎么样:

    $output = preg_replace($_BOOL_, '', preg_grep($_BOOL_, $input));
    

    编辑:再看看你的问题,我不确定我们谈论的是同一件事。对于输入数组中的每个字符串, preg_replace preg_filter

    推荐文章