我有一堆wiki标记,有时候人们只是随意在wiki标记中抛出html,并以某种方式维基百科随它一起滚动,就像它为各种其他形式很差的维基标记。我想匹配div内的所有内容。div标签的递归正则表达式(不是试图用正则表达式解析html)
我需要递归地找到所有
new Regex(@"\
(?) # opening(?> # now match...
[^(\
)(\)]+ # any characters except divs| # or
\
(?) # a opening div, increasing the depth counter| # or
\ (?) # a closing div, decreasing the depth counter
)* # any number of times
(?(DEPTH)(?!)) # until the depth counter is zero again
\ # then match the closing fix",
RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
也许我应该用另一种方法来分析这一点,但在这一点上,这是我需要的最后的正则表达式语句。
下面是一个例子:
Find more about '''{{{display|{{{1|{{PAGENAME}}}}}}}}''' on Wikipedia's [[Wikipedia:Wikimedia sister projects|sister projects]]:
}}{{#ifeq:{{{b}}}|no||[[File:Wikibooks-logo.svg|25px|link=b:Special:Search/{{{b|{{{1|{{PAGENAME}}}}}}}}|Search Wikibooks]] [[b:Special:Search/{{{b|{{{1|{{PAGENAME}}}}}}}}|Textbooks]] from Wikibooks
}}{{#ifeq:{{{q}}}|no||[[File:Wikiquote-logo.svg|25px|link=q:Special:Search/{{{q|{{{1|{{PAGENAME}}}}}}}}|Search Wikiquote]] [[q:Special:Search/{{{q|{{{1|{{PAGENAME}}}}}}}}|Quotations]] from Wikiquote
}}{{#ifeq:{{{s}}}|no||{{#ifeq:{{{author|no}}}|yes|[[File:Wikisource-logo.svg|25px|link=s:Special:Search/Author:{{{s|{{{1|{{PAGENAME}}}}}}}}|Search Wikisource]] [[s:Special:Search/Author:{{{s|{{{1|{{PAGENAME}}}}}}}}|Source texts]] from Wikisource
|[[File:Wikisource-logo.svg|25px|link=s:Special:Search/{{{s|{{{1|{{PAGENAME}}}}}}}}|Search Wikisource]] [[s:Special:Search/{{{s|{{{1|{{PAGENAME}}}}}}}}|Source texts]] from Wikisource
}}}}{{#ifeq:{{{commons}}}|no||[[File:Commons-logo.svg|25px|link=commons:Special:Search/{{{commons|{{{1|{{PAGENAME}}}}}}}}|Search Commons]] [[commons:Special:Search/{{{commons|{{{1|{{PAGENAME}}}}}}}}|Images and media]] from Commons
}}{{#ifeq:{{{n}}}|no||[[File:Wikinews-logo.svg|25px|link=n:Special:Search/{{{n|{{{1|{{PAGENAME}}}}}}}}|Search Wikinews]] [[n:Special:Search/{{{n|{{{1|{{PAGENAME}}}}}}}}|News stories]] from Wikinews
}}{{#ifeq:{{{v}}}|no||[[File:Wikiversity-logo-Snorky.svg|25px|link=v:Special:Search/{{{v|{{{1|{{PAGENAME}}}}}}}}|Search Wikiversity]] [[v:Special:Search/{{{v|{{{1|{{PAGENAME}}}}}}}}|Learning resources]] from Wikiversity
}}{{#ifeq:{{{species|no}}}|no||[[File:Wikispecies-logo.svg|25px|link=species:Special:Search/{{{species|{{{1|{{PAGENAME}}}}}}}}|Search Wikispecies]] [[species:Special:Search/{{{species|{{{1|{{PAGENAME}}}}}}}}|{{{species|{{{1|{{PAGENAME}}}}}}}}]] from Wikispecies}}
感谢
+4
诚然,没有任何Wiki标记的知识,不会简单地剥离所有的HTML标签是一个更好的主意?因为就目前而言,与问题标题相反,你确实试图用正则表达式解析HTML标记;) –
2011-05-17 13:46:39
+0
这可能是失败主义者,但通常我们在同一个句子中有'递归'和'正则表达'这两个单词,'不可能“并不遥远;除非您手动运行自己的状态机来跟踪深度,自己调用多个正则表达式。正则表达式的状态机不能处理我认为的这种事情。但是,如果你说出你想要的那个例子,那可能会有所帮助。 –
2011-05-17 13:48:05
+0
“(不是试图用正则表达式解析html)”< - 哈哈哈,很好!很明显,你用“html”和“regex”阅读了其他一些问题。 ;-) –
2011-05-17 13:48:10