正则表达式从CDATA解析出的HTML用C# [英] Regex to parse out html from CDATA with C#
本文介绍了正则表达式从CDATA解析出的HTML用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想解析出返回包裹在CDATA任何HTML数据
I would like to parse out any HTML data that is returned wrapped in CDATA.
例如<![CDATA [< ;表>< TR>< TD>核准< / TD>< / TR>< /表>]]>
谢谢!
推荐答案
来处理你的例子表达是
\<\!\[CDATA\[(?<text>[^\]]*)\]\]\>
当组文本将包含您的HTML。
Where the group "text" will contain your HTML.
您所需要的C#代码为:
The C# code you need is:
using System.Text.RegularExpressions;
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"\<\!\[CDATA\[(?<text>[^\]]*)\]\]\>", options);
string input = @"<![CDATA[<table><tr><td>Approved</td></tr></table>]]>";
// Check for match
bool isMatch = regex.IsMatch(input);
if( isMatch )
Match match = regex.Match(input);
string HTMLtext = match.Groups["text"].Value;
end if
输入变量在那里只是为了使用样本输入你提供
The "input" variable is in there just to use the sample input you provided
这篇关于正则表达式从CDATA解析出的HTML用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文