NotDan
NotDan

Reputation: 32213

Regular Expressions Ignore Case in search but not replace

In C#, I want to be able to generically replace text, ignoring case in the search but not in the replace (kind of?). Here is an example:

I have a list that looks like this:

Site -> Place

Stuff -> Things

etc...

Then I want to call ConvertMyString("Site") and have it return "Place".

So far I have this working, BUT...

If I call ConvertMyString("site"), I would like it to return "place" (lowercase).

Is there an easy way to do this with a RegEx or something without having to put all uppercase and lowercase versions in the list?

Upvotes: 1

Views: 1596

Answers (2)

h3n
h3n

Reputation: 5248

or use this online tool: http://gskinner.com/RegExr/

Upvotes: 0

The Archetypal Paul
The Archetypal Paul

Reputation: 41749

You could use a MatchEvaluator to manipulate the replacement string? It gets handed the matched string so you could look at the case of that and assemble a replacement. Seemsa bit overkill, though

Upvotes: 3

Related Questions