我試圖找出下一個文本文件一種表達式搜索多表達:優化在C#中的正則表達式中的文本
<<>[some text][newline][some text]<>>
這裏美中不足的是,新行可以有很多之前我們發現結束標記<>>
我試過以下的正則表達式
<(.*?\n.*?)>
它完美的作品找到表達單線分,但我也需要發現用各種線條劃分的表達式。
我嘗試下面的表達式也:
<(.*?\n.*?)*>
但搜索它是導致超時, 請幫幫忙?
用於搜索示例文字:
<p class=3DMsoNormal style=3D'margin-top:12.0pt;margin-right:0cm;margin-bot=
tom:
0cm;margin-left:148.85pt;margin-bottom:.0001pt;text-indent:-148.85pt;
tab-stops:148.85pt right 16.0cm'><b style=3D'mso-bidi-font-weight:normal'><=
span
style=3D'font-family:"Calibri","sans-serif"'>RISK DETAILS<span style=3D'mso=
-tab-count:
1'> =
&nb=
sp; =
</span></span></b><span
style=3D'font-family:"Calibri","sans-serif"'>Your home is described as
<q_1><o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>The
construction of your home is <q_2><o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>The
main roof material is <q_3><o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>Your
home was built in <q_4><o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>Your
<span class=3DGramE>home <q_5> double</span> keyed deadlocks to all
external doors<o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>Your
home <q_6> keyed locks or grilles on all windows<o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>Your
home has <q_7> alarm installed<o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt'><span style=3D'font-family:"Cal=
ibri","sans-serif"'>Your
home <q_8> connected to mains water supply<o:p></o:p></span></p>
一些例子: 例1: 文本進行搜索:
<span
style=3D'color:blue'><o:p></o:p></span></span></p>
</td>
<td width=3D103 valign=3Dtop style=3D'width:77.5pt;padding:0cm 5.4pt 0cm =
0cm'>
<p class=3DMsoNormal align=3Dright style=3D'margin-top:3.0pt;margin-right=
:0cm;
margin-bottom:0cm;margin-left:0cm;margin-bottom:.0001pt;text-align:right;
tab-stops:155.95pt'><span style=3D'font-family:"Calibri","sans-serif"'><=
<span
class=3DSpellE>spec_contents_value</span>><span style=3D'color:blue'><=
o:p></o:p></span></span></p>
</td>
</tr>
</table>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt;text-indent:-148.85pt;tab-stops:
148.85pt right 453.55pt'><span style=3D'font-family:"Calibri","sans-serif"'=
><o:p> </o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt;text-indent:-148.85pt;tab-stops:
148.85pt right 453.55pt'><span style=3D'font-family:"Calibri","sans-serif"'=
>Unspecified
Valuables<b style=3D'mso-bidi-font-weight:normal'><span style=3D'mso-tab-co=
unt:
1'> =
</=
span></b><valuables><o:p></o:p></span></p>
<p class=3DMsoNormal style=3D'margin-top:0cm;margin-right:0cm;margin-bottom=
:0cm;
margin-left:148.85pt;margin-bottom:.0001pt;text-indent:-148.85pt;tab-stops:
148.85pt right 453.55pt'><span style=3D'font-family:"Calibri","sans-serif"'=
>Specified
Valuables<b style=3D'mso-bidi-font-weight:normal'><span style=3D'mso-tab-co=
unt:
1'> =
&nb=
sp; </span></b><<spanclass=3DSpellE>spec_valuables_ni</span>>=
<o:p></o:p></span></p>
我希望我的Regex.Match模式能夠搜索:
<=
<span
class=3DSpellE>spec_contents_value</span>>
或任何< ...跨越多行的>模式。但不在同一行上。
格式的代碼,以便我們能提供你想要的正則表達式。 – 2014-11-04 08:59:37
感謝@ nu11p01n73R進行編輯:-) – mohits00691 2014-11-04 09:07:27
@ mohits00691它是否&lt; <你的原始代碼? – nu11p01n73R 2014-11-04 09:08:08