/^\/\/.|:\//
为什么这个正则表达式 可以匹配 绝对路径形如:
http://example.com中的 ://
我的理解是^\/ 首先是以/开头才行,明显这个是以h开头的啊,麻烦给指点下

解决方案 »

  1.   


    <?php
    $s = "http://www.domain.com/";preg_match('/^\/\/.|:\//',$s,$mat);
    echo print_r($mat);
    ?>输出的结果为Array ( [0] => :/ )
      

  2.   


    只要给定的字符串包含有匹配的结果。哪么它就符合要求。你要从http开始后面任意为一个匹配段可以这样写
    <?php
    $s = "http://www.domain.com/";//preg_match('/^\/\/.|:\//',$s,$mat);
    preg_match('/^http:\/\/(.*)/i', $s,$mat);
    echo print_r($mat);
    ?>输出Array ( [0] => http://www.domain.com/ [1] => www.domain.com/ )
      

  3.   


    只要给定的字符串包含有匹配的结果。哪么它就符合要求。你要从http开始后面任意为一个匹配段可以这样写
    <?php
    $s = "http://www.domain.com/";//preg_match('/^\/\/.|:\//',$s,$mat);
    preg_match('/^http:\/\/(.*)/i', $s,$mat);
    echo print_r($mat);
    ?>输出Array ( [0] => http://www.domain.com/ [1] => www.domain.com/ )
    你写这个我懂,但是我提出的问题 还是没解决啊