我在隐藏字段中发送一些 html,在服务器端我将使用正则表达式解析它。目前我能够解析
<div id="4059">asd</div>
下面的代码在 match.Groups[2] 中给出了“id”,在 match.Groups[4] 中给出了“4059”,“div”出现在第一个索引处,第三个为空。
string regex2 = @"<(?<Tag_Name>(a)|div)\b[^>]*?\b(?<URL_Type>(?(1)id))\s*=\s*(?:""(?<URL>(?:\\""|[^""])*)""|'(?<URL>(?:\\'|[^'])*)')";
var matches = Regex.Matches(myDiv, regex2, RegexOptions.IgnoreCase | RegexOptions.Singleline);
var links = new List<string>();
foreach (Match item in matches)
{
if (item.Groups[2].Value == "div")
{
employee.ID = item.Groups[4].Value;
}
]
有人可以编辑这个正则表达式吗?
<(?<Tag_Name>(a)|div)\b[^>]*?\b(?<URL_Type>(?(1)id))\s*=\s*(?:""(?<URL>(?:\\""|[^""])*)""|'(?<URL>(?:\\'|[^'])*)')
这样我就可以解析
<div id="5094" fieldA="asd" fieldB="def" fieldC="ghi"></div>
并且也可以添加字段。
我还应该在这里提到我正在开发一个自定义控件,并且当我在我的项目中添加它时,我不能使用 HTML AGILITY PACK 作为程序集冲突。