【问题标题】:remove all slashes regex删除所有斜杠正则表达式
【发布时间】:2012-02-14 23:19:49
【问题描述】:

我有字符串"h///e/ll\\o\//\"。 需要多次删除所有斜线来回斜线有人可以告诉我正则表达式吗?

它用于 php preg_replace();

【问题讨论】:

    标签: php regex replace


    【解决方案1】:

    试试这个:

    var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\"));
    // Output: string(5) "hello"
    

    http://codepad.org/PIjKsc9F

    也可以选择

    var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\'));
    // Output: string(5) "hello"
    

    http://codepad.org/0d5j9Mmm

    【讨论】:

      【解决方案2】:

      您不需要正则表达式来删除这些:

      $string = str_replace(array('/', '\\'), '', $string);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-01
        • 2012-12-03
        • 1970-01-01
        • 2011-03-09
        • 1970-01-01
        • 1970-01-01
        • 2021-07-11
        相关资源
        最近更新 更多