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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

copy data from one worksheet and disregard blank cells 6
Data Matching 2
data splitting 1
Formula help 2
data splitting 4
Parse and split string 3
How to return the class name from a class? 8
Help parsing string 3

Back
Top