I have a string, which represents part of xml.
string text ="word foo<tag foo='a' />another word "
and I need to replace particular words in this string. So I used this code:
Regex regex = new Regex("\\b" + co + "\\b", RegexOptions.IgnoreCase);
return regex.Replace(text, new MatchEvaluator(subZvyrazniStr));
static string subZvyrazniStr(Match m)
{
return "<FtxFraze>" + m.ToString() + "</FtxFraze>";
}
But the problem of my code is, that it also replaces string inside tags, which i don't want to. So what should I add, to replace words only outside tags?
Ex.: when I set variable co to "foo" I want to return "word <FtxFraze>foo</FtxFraze><tag foo='a' />another word"
Thanks