问这段真正是什么意思 ?preg_match('#^([^:]+): (.*)\s+$#', $str, $match

解决方案 »

  1.   

    搜索以#开始以#结束的、冒号前可以是任何非冒号的字符、冒号后可以是任何字符加任意个空格的字符串,文字描述太复杂,类似下面的例子吧:#asddsa: any charactor   #这个类似聊天记录啊,系统日志等等。
      

  2.   

    <?php
    //楼上的:#是定界符号 ,跟| 和 / 以及@是一样的。所以不是#开头的行也可以匹配!
    $ary = array(
    '#sdf:s #'   //这个不能匹配因为结尾没空
    ,'######::::: s '          //这个能
    ,'sfjldkfjal' //这个不能,因为没有:
    );
    echo "<pre>";
    foreach($ary as $str){
    //echo $str;
    preg_match('#^([^:]+):(.*)\s+$#', $str, $match);
    var_dump($match);
    }
    echo "</pre>";
    ?>
    //结果:
    array(0) {
    }
    array(3) {
      [0]=>
      string(14) "######::::: s "
      [1]=>
      string(6) "######"
      [2]=>
      string(6) ":::: s"
    }
    array(0) {
    }
      

  3.   

    哈 我也来回答一个
    preg_match('#^([^:]+): (.*)\s+$#', $str, $match 
    就是说,所匹配字符串的条件如下:1)非:的字符开头的 
    2)并且中间得包含一个:
    3)以空白(包括换行,制表,空格)结尾
      

  4.   


    高手啊,为什么我这个匹配不出来啊, 
    $str = ":adsd:sss  awww";
    preg_match('#^([^:]+):(.*)\s+$#', $str, $match);  print_r($match);
      

  5.   

    ":adsd:sss     awww";不匹配,原因有:
    1 开头不能是“:”
    2 结尾要有“空格”
      

  6.   


    您好 我知道这个正则的意义,
    但是:$str = ":adsd:sss     awww";
    preg_match('#^([^:]+):(.*)\s+$#', $str, $match);  print_r($match);
    中 preg_match 中的 $match, 是应该能返回$str中所能匹配的部分啊, 例如 红色部分呢?
      

  7.   


    比如你看<?php
    $html = '<div id="biuuu">51CTO</div>
    <div id="biuuu_2">51CTO2</div>
    <div id="biuuu_3">51CTO3</div>';preg_match_all('/\"([a-z0-9_]+)\">([^a])<\/div>/',$html,$result);
    print_r($result); 
    这段正则只是匹配提取出其中的所需要的那部分,并不是匹配从开头  到  结尾 这个整体啊??
      

  8.   


    我知道啊^  表示以什么开头$  表示以什么结尾 ":adsd:sss awww" 红色部分的开头结尾都符合条件啊?
      

  9.   

    你理解错了!(我的理解是)在这里,^应该是“一行的开头”;$是“一行的结尾”。它们是“零宽”---不代表具体的字符(只占一个位置),就像\b代表单词边界一样(有些解释器是用\<代表单词边界)。