Hello Bob,
How can I use RegEx to search for a number of strings and replace them
with upper case versions of themselves?
Thanks
You cannot use a replacement pattern to indicate you want the found match
to become upper case. You can however use a MatchEvaluator to accomplish
this:
static Regex rx = new Regex("\b(stringa|stringb|stringc)\b", RegexOptions.Compiled
| RegexOptions.IgnoreCase);
public string UpperSpecialWords(string input)
{
return rx.Replace(input, new MatchEvaluator(UpperSpecialWordsImpl));
}
private string UpperSpecialWordsImpl(Match m)
{
return m.Value.ToUpper();
}
In the MatchEvaluator function you can manipulate the contents of the match
and return them as a string. These changes will be merged with the original
resultign in exactly what you need.
Jesse