匹配嵌套HTML标记的正则表达式

by Alpha 1. September 2009 14:46

1.来自:http://www.unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm

<div[^>]*>[^<>]*(((?'Open'<div[^>]*>)[^<>]*)+((?'-Open'</div>)[^<>]*)+)*(?(Open)(?!))</div>

能够匹配<div><div></div><div>这样的,也就是中间只能是div标记,如果有其他标记(比如<p></p>则匹配失败)。

2.我根据上面这个写的,能够解决上述正则所不能匹配的嵌套HTML标记。

<div[^>]*>(?<questionmain>(.|\n)*?(((?'Open'<div[^>]*>)(.|\n)*?)+((?'-Open'</div>)(.|\n)*?)+)*(?(Open)(?!)))</div>

Tags: , Views:893

.Net相关

Comments

9/3/2009 2:50:03 AM #

helloshp

不错!受用了!

helloshp People's Republic of China |

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen  浙ICP备09023819号  

关于作者

Alpha

1.男
2.已婚
3.网虫
4.宝宝叫yoyo

Calendar

<<  September 2010  >>
MondayTuesdayWednesdayThursdayFridaySaturdaySunday
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS