У меня есть строка, из которой мне нужно удалить все HTML и XML. Я не очень хорош с регулярными выражениями. Для HTML я нашел действительно полезный код:
snippet = Regex.Replace(snippet, "<.*?>", "");
В настоящее время я делаю это для XML:
while (snippet.IndexOf("<xml>") != -1)
{
int startLoc = snippet.IndexOf("<xml>");
int endLoc = snippet.IndexOf("</xml>");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 6);
}
while (snippet.IndexOf("<style>") != -1)
{
int startLoc = snippet.IndexOf("<style>");
int endLoc = snippet.IndexOf("</style>");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 8);
}
// only required for chrome and IE
// removes - <object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui">
while (snippet.IndexOf("<object") != -1)
{
int startLoc = snippet.IndexOf("<object");
int endLoc = snippet.IndexOf("id=\"ieooui\">");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 12);
}
// removes - <object id="ieooui" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D">
while (snippet.IndexOf("<object") != -1)
{
int startLoc = snippet.IndexOf("<object");
int endLoc = snippet.IndexOf("classid=\"clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D\"");
snippet = snippet.Remove(startLoc, (endLoc - startLoc) + 52);
}
Что очень неопрятно. Может ли кто-нибудь1 предложить мне также регулярные выражения для xml, особенно для:
<object id="ieooui" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D">
и
<object classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id="ieooui">
Спасибо за тонну.