Here is this implementation. I used to highlight special replacement strings from content and localization.
protected string FindAndTranslateIn(string content) { return Regex.Replace(content, @"\{\^(.+?);(.+?)?}", new MatchEvaluator(TranslateHandler), RegexOptions.IgnoreCase); } public string TranslateHandler(Match m) { if (m.Success) { string key = m.Groups[1].Value; key = FindAndTranslateIn(key); string def = string.Empty; if (m.Groups.Count > 2) { def = m.Groups[2].Value; if(def.Length > 1) { def = FindAndTranslateIn(def); } } if (group == null) { return Translate(key, def); } else { return Translate(key, group, def); } } return string.Empty; }
From the delegate of the conformity evaluator, you return everything you want to replace, so when I have the results you will have bold tags and a code call, mine also supports recursion, so itβs a little more complicated for your needs, but you can just hide the example for your needs .
This is equivalent to doing an iteration over a set of matches and doing parts of specifying replacement methods. It just saves you some code, and you can use the fancy shmancy delegate.
source share