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(strin ga|stringb|stri ngc)\b", RegexOptions.Co mpiled
| RegexOptions.Ig noreCase);
public string UpperSpecialWor ds(string input)
{
return rx.Replace(inpu t, new MatchEvaluator( UpperSpecialWor dsImpl));
}
private string UpperSpecialWor dsImpl(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