dongzaobei0942 2015-07-11 20:18
浏览 12
已采纳

PHP中preg_replace函数的解释[重复]

This question already has an answer here:

The preg_replace() function has so many possible values, like:

    <?php
    $patterns = array('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/', '/^\s*{(\w+)}\s*=/');
    $replace = array('\3/\4/\1\2', '$\1 =');
    echo preg_replace($patterns, $replace, '{startDate} = 1999-5-27');

What does:

 \3/\4/\1\2

And:

/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/','/^\s*{(\w+)}\s*=/ 

mean?

Is there any information available to help understand the meanings at one place? Any help or documents would be appreciated! Thanks in Advance.

</div>
  • 写回答

2条回答 默认 最新

  • dony113407 2015-07-11 21:24
    关注

    Take a look at http://www.tutorialspoint.com/php/php_regular_expression.htm

    \3 is the captured group 3
    \4 is the captured group 4
    ...an so on...

    \w means any word character.
    \d means any digit.
    \s means any white space.
    + means match the preceding pattern at least once or more.
    * means match the preceding pattern 0 times or more.
    {n,m} means match the preceding pattern at least n times to m times max.
    {n} means match the preceding pattern exactly n times.
    (n,} means match the preceding pattern at least n times or more.
    (...) is a captured group.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?