PHP regex delimiters, / vs. | vs. {} , what are the differences?

后端 未结 2 626
孤城傲影
孤城傲影 2020-12-19 08:59

In the PHP manual of PCRE, http://us.php.net/manual/en/pcre.examples.php, it gives 4 examples of valid patterns:

  • /<\\/\\w+>/
2条回答
  •  误落风尘
    2020-12-19 09:43

    No difference, except the closing delimiter cannot appear without escaping.

    This is useful when the standard delimiter is used a lot, e.g. instead of

    preg_match("/^http:\\/\\/.+/", $str);
    

    you can write

    preg_match("[^http://.+]", $str);
    

    to avoid needing to escape the /.

提交回复
热议问题