Regex gurus help needed

  • Thread starter Thread starter SM
  • Start date Start date
S

SM

I want a string
abc:{def} ijk:{xyx}

to be modified to

abc:{DEF} ijk{XYZ}

just strings inside {} should be capitalized.

can someone help
 
SM said:
I want a string
abc:{def} ijk:{xyx}

to be modified to

abc:{DEF} ijk{XYZ}

just strings inside {} should be capitalized.

can someone help

I think you have to use a MatchEvaluator.

// demonstration calling code
// assuming:
// using System.Text.RegularExpressions
string s = "abc{def}";
string t = Regex.Replace(s, "{.*}", new MatchEvaluator(MatchToUpper));


// somewhere else
static string MatchToUpper(Match m)
{
return m.Value.ToUpper();
}
 
string t = Regex.Replace(s, "{.*}", new MatchEvaluator(MatchToUpper));

The regex should be "\{.*?\}". Otherwise the curlies have special
meaning and the * will match greedily, so you'd get only one match in
the sample expression instead of two.



Oliver Sturm
 
Back
Top