<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP中的递归正则</title>
	<atom:link href="http://iregex.org/blog/recursive-regex-in-php.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iregex.org/blog/recursive-regex-in-php.html</link>
	<description>原创、翻译、转载关于正则表达式的文章</description>
	<lastBuildDate>Fri, 18 May 2012 03:20:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Vigo</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-5911</link>
		<dc:creator>Vigo</dc:creator>
		<pubDate>Tue, 21 Dec 2010 08:00:59 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-5911</guid>
		<description>&lt;code lang=&quot;html&quot;&gt;&lt;div class=&quot;tatt&quot; id=&quot;aimg_49645_menu&quot; style=&quot;position: absolute; display: none&quot;&gt;      //我想用php的preg匹配这个div和下面的最后一个div之间的内容
&lt;div class=&quot;crly&quot;&gt;
&lt;div class=&quot;y&quot;&gt;2010-11-23 14:19 上传&lt;/div&gt;
&lt;a href=&quot;http://www.xxx.com/forum-attachment-aid-NDk2NDV8YjQ3NTE1ZmJ8MTI5MjkxNzY4MXww-nothumb-yes.html&quot; title=&quot;001.jpg 下载次数:0&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;下载附件&lt;/strong&gt; &lt;span class=&quot;xs0&quot;&gt;(69.18 KB)&lt;/span&gt;&lt;/a&gt;

&lt;/div&gt;
&lt;div class=&quot;mncr&quot;&gt;&lt;/div&gt;
&lt;/div&gt;                  //匹配这些内容有办法用递归吗？弄了三天也弄不出来，我实在太菜了
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tatt&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;aimg_49645_menu&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;position: absolute; display: none&quot;</span>&gt;</span> &nbsp; &nbsp; &nbsp;//我想用php的preg匹配这个div和下面的最后一个div之间的内容<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;crly&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y&quot;</span>&gt;</span>2010-11-23 14:19 上传<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.xxx.com/forum-attachment-aid-NDk2NDV8YjQ3NTE1ZmJ8MTI5MjkxNzY4MXww-nothumb-yes.html&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;001.jpg 下载次数:0&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;_blank&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">strong</span>&gt;</span>下载附件<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">strong</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xs0&quot;</span>&gt;</span>(69.18 KB)<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mncr&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//匹配这些内容有办法用递归吗？弄了三天也弄不出来，我实在太菜了</div></td></tr></tbody></table></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vigo</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-5910</link>
		<dc:creator>Vigo</dc:creator>
		<pubDate>Tue, 21 Dec 2010 07:59:14 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-5910</guid>
		<description>
   //我想用php的preg匹配这个div和下面的最后一个div之间的内容
2010-11-23 14:19 上传
&lt;a href=&quot;http://www.xxx.com/forum-attachment-aid-NDk2NDV8YjQ3NTE1ZmJ8MTI5MjkxNzY4MXww-nothumb-yes.html&quot; title=&quot;001.jpg 下载次数:0&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;下载附件&lt;/strong&gt; (69.18 KB)&lt;/a&gt;



     //匹配这些内容有办法用递归吗？弄了三天也弄不出来，我实在太菜了</description>
		<content:encoded><![CDATA[<p>//我想用php的preg匹配这个div和下面的最后一个div之间的内容<br />
2010-11-23 14:19 上传<br />
<a href="http://www.xxx.com/forum-attachment-aid-NDk2NDV8YjQ3NTE1ZmJ8MTI5MjkxNzY4MXww-nothumb-yes.html" title="001.jpg 下载次数:0" rel="nofollow"><strong>下载附件</strong> (69.18 KB)</a></p>
<p>     //匹配这些内容有办法用递归吗？弄了三天也弄不出来，我实在太菜了</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-4942</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Sun, 07 Nov 2010 12:59:46 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-4942</guid>
		<description>这个问题不难. 给我发个样本文件, 告诉我你使用什么语言, 我帮你写个例程序? 我的邮箱: rex [at] zhasm [dot] com.</description>
		<content:encoded><![CDATA[<p>这个问题不难. 给我发个样本文件, 告诉我你使用什么语言, 我帮你写个例程序? 我的邮箱: rex [at] zhasm [dot] com.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tocky</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-4922</link>
		<dc:creator>tocky</dc:creator>
		<pubDate>Sat, 06 Nov 2010 01:58:25 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-4922</guid>
		<description>hello，看了你的博客，知道你是正则高手，真厉害啊！想向你请教一个问题，我想提取出html中含有特定字符串的URL。不知正则该怎么写？例如：html文档中，我的目标URL中含有abcde这个特定字符串，我想提取的URL就是http://www.baidu.com/pub/abcde&amp;classid=4&amp;date=2010-11-5&amp;sort=1 这种的,该怎么写呢？弄了很久都没写出来，向你求助，希望能帮我解答下，谢谢！</description>
		<content:encoded><![CDATA[<p>hello，看了你的博客，知道你是正则高手，真厉害啊！想向你请教一个问题，我想提取出html中含有特定字符串的URL。不知正则该怎么写？例如：html文档中，我的目标URL中含有abcde这个特定字符串，我想提取的URL就是http://www.baidu.com/pub/abcde&amp;classid=4&amp;date=2010-11-5&amp;sort=1 这种的,该怎么写呢？弄了很久都没写出来，向你求助，希望能帮我解答下，谢谢！</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3766</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Wed, 04 Aug 2010 01:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3766</guid>
		<description>我写了一个简单的标签格式化脚本，一会写发一篇博文介绍一下，希望有所帮助。</description>
		<content:encoded><![CDATA[<p>我写了一个简单的标签格式化脚本，一会写发一篇博文介绍一下，希望有所帮助。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 神の呼出</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3762</link>
		<dc:creator>神の呼出</dc:creator>
		<pubDate>Tue, 03 Aug 2010 16:13:58 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3762</guid>
		<description>我想格式化的文本为任意html代码，目前代码里面的标签是平衡的，即有个&lt;code&gt;&lt;label&gt;&lt;/code&gt;就有一个&lt;code&gt;&lt;/label&gt;&lt;/code&gt;相对应，当然也包含独立标签如&lt;code&gt;&lt;img /&gt;&lt;/code&gt;、&lt;code&gt;&lt;meta /&gt;&lt;/code&gt;等，需要格式化的代码为一长字符串，即不包含任意\t，\n等空白符。我需要的是将这一段代码按如下方式格式化：
每出现一组成对标签，即缩进一个tab
最内层的成对标签应处于同行
若出现的是独立标签，则将其与它的父标签（一定是成对的）置于同一行
所有文字与其父标签置于同一行
表单独立元素input实现同级缩进（即不在同一行）
若可以的话，对不平衡组也进行格式化（按出现顺序增加tab）。

这个用js很方便，但是要用php处理生成网页就麻烦了。WordPress自带的函数经常把\n和\t去掉，给出一大堆东西。虽然说没人会在意源代码，但是我有点完美主义，最好把html源代码也搞的漂亮些。

我能写出的正则如
&lt;code&gt;
$pattern = &quot;/&lt;[\w]+[^&gt;]*&gt;.*&lt;\/\\2&gt;/&quot;;
&lt;/code&gt;
这样只能贪婪匹配，却并无方法匹配如
&lt;code&gt;
&lt;div&gt;
    &lt;div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/code&gt;
这样的形式，若用&lt;code&gt;(?R)&lt;/code&gt;又没有办法使用逆向引用。还有判断独立标签我用的是零宽断言&lt;code&gt;(?!=\/)&lt;/code&gt;（因为独立标签末尾应该是&lt;code&gt; /&gt;&lt;/code&gt;这样的）似乎也不是很好，因为有时带有属性(class,id,src等)的标签就没法匹配。所以虽然比较麻烦，但还是请高手赐教。无论写出的正则多长都没关系。谢谢！

PS:我现在的做法有点傻，就是先用正则找到一个成对标签的头，即&lt;code&gt;&lt;label&gt;&lt;/code&gt;然后每找到一个&lt;code&gt;&lt;label&gt;&lt;/code&gt;加一个tab,若找到的是&lt;code&gt;&lt;/label&gt;&lt;/code&gt;则减少一个tab，但显然不符合正则的精神啊</description>
		<content:encoded><![CDATA[<p>我想格式化的文本为任意html代码，目前代码里面的标签是平衡的，即有个</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;label&gt;</div></td></tr></tbody></table></div>
<p>就有一个</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;/label&gt;</div></td></tr></tbody></table></div>
<p>相对应，当然也包含独立标签如</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;img /&gt;</div></td></tr></tbody></table></div>
<p>、</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;meta /&gt;</div></td></tr></tbody></table></div>
<p>等，需要格式化的代码为一长字符串，即不包含任意\t，\n等空白符。我需要的是将这一段代码按如下方式格式化：<br />
每出现一组成对标签，即缩进一个tab<br />
最内层的成对标签应处于同行<br />
若出现的是独立标签，则将其与它的父标签（一定是成对的）置于同一行<br />
所有文字与其父标签置于同一行<br />
表单独立元素input实现同级缩进（即不在同一行）<br />
若可以的话，对不平衡组也进行格式化（按出现顺序增加tab）。</p>
<p>这个用js很方便，但是要用php处理生成网页就麻烦了。WordPress自带的函数经常把\n和\t去掉，给出一大堆东西。虽然说没人会在意源代码，但是我有点完美主义，最好把html源代码也搞的漂亮些。</p>
<p>我能写出的正则如</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$pattern = &quot;/&lt;[\w]+[^&gt;]*&gt;.*&lt;\/\\2&gt;/&quot;;</div></td></tr></tbody></table></div>
<p>这样只能贪婪匹配，却并无方法匹配如</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div&gt;<br />
&nbsp; &nbsp; &lt;div&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</div></td></tr></tbody></table></div>
<p>这样的形式，若用</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(?R)</div></td></tr></tbody></table></div>
<p>又没有办法使用逆向引用。还有判断独立标签我用的是零宽断言</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(?!=\/)</div></td></tr></tbody></table></div>
<p>（因为独立标签末尾应该是</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;/&gt;</div></td></tr></tbody></table></div>
<p>这样的）似乎也不是很好，因为有时带有属性(class,id,src等)的标签就没法匹配。所以虽然比较麻烦，但还是请高手赐教。无论写出的正则多长都没关系。谢谢！</p>
<p>PS:我现在的做法有点傻，就是先用正则找到一个成对标签的头，即</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;label&gt;</div></td></tr></tbody></table></div>
<p>然后每找到一个</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;label&gt;</div></td></tr></tbody></table></div>
<p>加一个tab,若找到的是</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;/label&gt;</div></td></tr></tbody></table></div>
<p>则减少一个tab，但显然不符合正则的精神啊</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3754</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Tue, 03 Aug 2010 00:14:19 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3754</guid>
		<description>这个问题很有意思。能否详细地描述一下您的问题？例如，需要格式化的文本是什么，格式化之后的文本是什么的，格式化中，有哪些问题。等等。上面您的描述再加上一些具体的格式化的例子就更好了。谢谢。</description>
		<content:encoded><![CDATA[<p>这个问题很有意思。能否详细地描述一下您的问题？例如，需要格式化的文本是什么，格式化之后的文本是什么的，格式化中，有哪些问题。等等。上面您的描述再加上一些具体的格式化的例子就更好了。谢谢。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 神の呼出</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3750</link>
		<dc:creator>神の呼出</dc:creator>
		<pubDate>Mon, 02 Aug 2010 15:23:05 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3750</guid>
		<description>我想用PHP格式化html代码，可是匹配相当麻烦啊。
比如
&lt;code&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/code&gt;
和
&lt;code&gt;
&lt;div&gt;
    &lt;div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/code&gt;
这样只有递归正则才能实现，但是还有一些标签，如：
&lt;code&gt;
&lt;img src=&quot;&quot; /&gt;
&lt;/code&gt;
等并非成对出现。这样就麻烦了。更何况不知道代码有几层，更不要说如：
&lt;code&gt;
&lt;div&gt;
    some content&lt;img src=&quot;&quot; /&gt;
    &lt;div&gt;
        &lt;img src=&quot;&quot; /&gt;
        &lt;ul&gt;
            &lt;li&gt;some content&lt;/li&gt;
            &lt;li&gt;some content&lt;/li&gt;
            ...
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/code&gt;
这样乱七八糟的代码了。请教高手，要将没一个标签按层匹配放入数组，正则到底能不能实现？若能，该怎么写？谢谢！
PS: 逆向引用是不是不能和递归并存？</description>
		<content:encoded><![CDATA[<p>我想用PHP格式化html代码，可是匹配相当麻烦啊。<br />
比如</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div&gt;&lt;/div&gt;<br />
&lt;div&gt;&lt;/div&gt;</div></td></tr></tbody></table></div>
<p>和</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div&gt;<br />
&nbsp; &nbsp; &lt;div&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</div></td></tr></tbody></table></div>
<p>这样只有递归正则才能实现，但是还有一些标签，如：</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;img src=&quot;&quot; /&gt;</div></td></tr></tbody></table></div>
<p>等并非成对出现。这样就麻烦了。更何况不知道代码有几层，更不要说如：</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;div&gt;<br />
&nbsp; &nbsp; some content&lt;img src=&quot;&quot; /&gt;<br />
&nbsp; &nbsp; &lt;div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;img src=&quot;&quot; /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;some content&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;some content&lt;/li&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div&gt;&lt;/div&gt;</div></td></tr></tbody></table></div>
<p>这样乱七八糟的代码了。请教高手，要将没一个标签按层匹配放入数组，正则到底能不能实现？若能，该怎么写？谢谢！<br />
PS: 逆向引用是不是不能和递归并存？</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3373</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Mon, 10 May 2010 22:06:34 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3373</guid>
		<description>如果您需要频繁地处理字符串的话，花一点时间学习正则表达式，会非常有帮助。</description>
		<content:encoded><![CDATA[<p>如果您需要频繁地处理字符串的话，花一点时间学习正则表达式，会非常有帮助。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 老张</title>
		<link>http://iregex.org/blog/recursive-regex-in-php.html/comment-page-1#comment-3370</link>
		<dc:creator>老张</dc:creator>
		<pubDate>Mon, 10 May 2010 13:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=84#comment-3370</guid>
		<description>正则用起来很麻烦，但是会用了很方便</description>
		<content:encoded><![CDATA[<p>正则用起来很麻烦，但是会用了很方便</p>
]]></content:encoded>
	</item>
</channel>
</rss>

