List Info

Thread: Case Insensitive Search with Sensitive Replace




Case Insensitive Search with Sensitive Replace
user name
2006-05-04 15:34:51
to summarize, a generic algorithm for such replaces is:

1. match (case insensitive) on *dmsap*
2. acquire a match say *dMsaP*
3. generate replace pattern *dMsfA* by whatever logic: pull
it off
DBase end; string process etc.
4. replace original text *dmsap* with new text *dMsfA*

e.g. in .NET it's done by using MatchEvaluator delegate.
The examplar
code below matches text *x* in the input text and replaces
it with *Y*
by invoking the delegate. The Delegate processes a match
(*x*) and then
returns modified text *Y* back to the calling
Regex.Replace() method:

using System;
using System.Text.RegularExpressions;

	class RegExSample
		//DOES: replaces every X with Y
	{//string is a return type of the function

		static string Replace(Match m)
		{
			// construct the string that will replaced the string in
the input
text matched by
			//delegate MatchEvaluator and return it
			string x = "Y";
			return x;
		}

		static void Main()
		{	//input string
			string text = "Replace X in here with Y, then match
it again: X";
			//print input
			Console.WriteLine("text=[" + text +
"]");
			//declare regex pattern
			string pattern = "X";

			//call static method Replace and replace every occurance
of X in
'text'
			string result = Regex.Replace(text, pattern, new
MatchEvaluator(RegExSample.Replace));

			//print result of Replace
			Console.WriteLine("result=[" + result +
"]");
			Console.WriteLine("\nPress Enter to Exit");
			Console.ReadLine();
		}
	}//end of class


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )