$str = "begin
xxxxxxxxxxxx
end
yyyyyyyyyyyyy
yy....
begin
xxxxxxx
end";preg_match_all("/begin\s+([^\s]+)\s+end/i", $str, $matches);
print_r($matches);

解决方案 »

  1.   


    ([^\s]+)
    如果xxxx 中包含回车换行,或者空格制表,怎么办?
    最后面为什么用 /i ?
      

  2.   


    function GetInformation($content){ $tmpArrayPattern[0] = "/\s+/";
    $tmpArrayPattern[1] = "/\t/";
    $tmpArrayPattern[2] = "/\n/";
    $tmpArrayPattern[3] = "/\r/";   
    $tmpArrayReplace[0] = "";
    $tmpArrayReplace[1] = "<tab>";
    $tmpArrayReplace[2] = "<newLine>";
    $tmpArrayReplace[3] = "<return>";
    ksort($tmpArrayPattern);
    ksort($tmpArrayReplace);
    $buffer = preg_replace($tmpArrayPattern,$tmpArrayReplace,$content);
    return $buffer;

    }
    给你提供一个我自己写的函数吧
    可以先把内容当中的回车啊换行啊空格啊什么的都剔除掉,然后在进行正则匹配
      

  3.   

    哪这个正则基本上没有办法写了.
    xxxxx内容里面可能有还会用begin和end呢.首先你要总结出字符串的规律来,要不然何谈正则.
      

  4.   

    回车换行用\r\n,对于一切空白字符,包括制表符,垂直制表符,空格等。\s都可以表示