我想从以下字符串中删除所有html标记并将其拆分而不使用句点(句号)作为匹配字符。以下sting是动态的,可以在list标签
中包含更多条件<li>This Offer cannot be redeemed with any other offer.</li><li>Only one Offer can be used at a time.</li><li>This Offer is not transferable.</li><li>......</li><li>....</li</ul></div>
我期待以下的感受
答案 0 :(得分:1)
String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);
试试这个
const string HTML_TAG_PATTERN = "<[^/li]>"; // may require some change
string safeString = Regex.Replace(yourString, HTML_TAG_PATTERN, string.Empty);
String[] myString = safeString.Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);
你也可以试试这个正则表达式
string acceptable = "li";
string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>";
string yourString= Regex.Replace(yourString, stringPattern, string.Empty);
String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);
答案 1 :(得分:0)
你可以删除所有的html标签并通过以下代码分割
string HTML_TAG_PATTERN = "<.*?>";
string str = @"<li>This Offer cannot be redeemed with any other offer.</li><li>Only one Offer can be used at a time.</li><li>This Offer is not transferable.</li><li>......</li><li>....</li</ul></div>";
string[] stString = Regex.Replace(str.Replace("</li>", "#$#"), HTML_TAG_PATTERN, string.Empty).Split("#$#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
答案 2 :(得分:-1)
如果您能够为<li>
提供身份证明,那么,
您可以尝试使用javascript代码,例如以下&gt;&gt;
var str=doccument.getElementById("liID").innerHTML;
根据您的应用,您可以尝试使用windows onload事件或任何特定事件。