What is Regular Expression?
It is a way of representing data using symbols. They are often used within matching,
searching or replacing algorithms.The term regular expression is often abbreviated
to regex or RE, RegEx or RegExp.
In this series of tutorials i will start from basic operations or Regular Expression
to more complex one with .Net C# code example. Hopefully you will find it very easy
to learn.
String Replacement with Case Sensitive and Insensitive Options
I am mentioning this basic replace functionality of Regular Expression class. Though
we have a replace functionality with String class. But problem with the lateral
is that it is case sensitive and if you need to do replacement with case insensitive you need to do a workaround. RegEx class provide us with a static method with parameter for Case ignoring. Following code shows difference between case sensitive options.
string text = "This is DotNetFocus blog. DotNetfocus blog is resource for ASP.NET.";
string pattern = "DotNetFocus"; //Simple string to match. keeping things simple in the start.
string replacewith = "MyBlog";
string updated = Regex.Replace(text, pattern, replacewith, RegexOptions.None);
Console.WriteLine(updated); //Output-> This is MyBlog blog. DotNetfocus blog is resource for ASP.NET.
updated = Regex.Replace(text, pattern, replacewith, RegexOptions.IgnoreCase);
Console.WriteLine(updated); //Output-> This is MyBlog blog. MyBlog blog is resource for ASP.NET.
Your feedback is an encourgement to write more.