0x0011 “内容1”
0x00A1 “内容2”怎么写这个表达式 谢谢

解决方案 »

  1.   


    $s = <<<eof
    0x0011 “内容1”
    0x00A1 “内容2”
    eof;
    preg_match_all('/0x[0-9A-Ea-e]+\s+“(.*?)”/i',$s,$arr);
    echo '<pre />';
    print_r($arr[1]);
      

  2.   


    preg_match_all('/0x[0-9a-e]+\s+“([^”]+)”/i',$s,$arr);
      

  3.   

    我期待的结果是:在文本中逐行读取:0x0011 “内容1”
                                      0x00A1 “内容2”
    然后利用正则表达式将 序号存放到一个数组中,将内容存放到一个数组中。
    Array_Num[];
    Array_Con[];
      

  4.   

    preg_match('/0x([a-f0-9]+)\s+"([^"]+)"/is',$str,$out);
      

  5.   

    楼上写的可以try一下 不对 
      

  6.   


    $str =<<<eof
    0x0011 “内容1”
    0x00A1 “内容2”
    eof;
    $pattern='/(.*?)\“(.*?)\”/is';
    preg_match_all($pattern,$str,$result);
    $Num=$result[1];
    $Con=$result[2];
      

  7.   

    $Array_Num = array();
    $Array_Con = array();
    $ArrayIndex = 0;
    $Pattern = "/^(0x[0-9A-F]+)/s+\"(.*)\";$/";
    foreach($Lines as $Line)
    {
    if(preg_match($Pattern, $Line, $Matches))
    {
    $Array_Num[$ArrayIndex] = $Matches[1];
    $Array_Con[$ArrayIndex] = $Matches[2];
    $ArrayIndex = $ArrayIndex + 1;
    }
    }
      

  8.   


    正则有点儿错误。
    纠正为
    $Pattern = "/^(0x[0-9A-F]+)/s+\"(.*)\"$/";