PHP: How to remove all regex?

How to remove all special regular expression characters from a string?

for example: I have a " /^bla\/bla\/bla\//i" that I want to be: " bla/bla/bla/"


I think this is not real in the context that I was thinking about. Thanks for your feedback.

+3
source share
3 answers

I'm not sure if this question answers your question, but are you probably looking for the preg_quote function ( http://us.php.net/manual/en/function.preg-quote.php )?

+1
source

, , , strtr(). , , , , , .

edit: , .

0
    <?php 
    $string = "/^bla\/bla\/bla\//i";
    $patterns = array(
        "/\/\^([\w]+)/i" => "$1/",
        "/[\/]{2,}i$/i" => "/",
        "/\\\/" => "",
        "/[\/]{2,}/" => "/",
        "/\/$/" => "",
    );
    echo preg_replace(array_keys($patterns),$patterns,$string);

    //OR, this:
    echo    "\n";

    $string = "/^bla\/bla\/bla\//i";
    $pattern = "/(?![\/\w]$)([\w]+)/";
    preg_match_all($pattern,$string,$matches);
    echo join('/',$matches[0]);
?>
0
source

Source: https://habr.com/ru/post/1731757/


All Articles