У меня более длинный текст и несколько ключевых слов. Я хочу выделить эти ключевые слова в моем тексте. Это не проблема с этим кодом:
private static string HighlightKeywords2(string keywords, string text)
{
// Swap out the ,<space> for pipes and add the braces
Regex r = new Regex(@", ?");
keywords = "(" + r.Replace(keywords, @"|") + ")";
// Get ready to replace the keywords
r = new Regex(keywords, RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Do the replace
return r.Replace(text, new MatchEvaluator(MatchEval2));
}
private static string MatchEval2(Match match)
{
if (match.Groups[1].Success)
{
return "<b>" + match.ToString() + "</b>";
}
return ""; //no match
}
Но когда слово «турнир» присутствует в тексте, а ключевое слово «тур» становится <b>tour</b>nament
Я хочу, чтобы он выделил полное слово: <b>tournament</b>
.
Как я могу это сделать?