我试图在文本文件中找到以下类型的表达式:
<<>[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>>
或者任何&lt; ...&gt;模式跨越多条线。但不是那些出现在同一条线上的人。
答案 0 :(得分:1)
答案 1 :(得分:1)
正则表达式怎么样
<[^&]*>
例如http://regex101.com/r/iV9lS4/3
<
匹配<
[^&]*
匹配&
以外的任何内容,包括换行符
>
匹配>
您还可以通过提供DOTALL .
运算符来使用(?s)
来匹配任何内容。
输入
<=
<span
class=3DSpellE>spec_contents_value</span>>