regex replace string c# code example
Example 1: c# regex replace
Regex.Replace(
"input string", @"[a-zA-Z]+", "replace string"
);
Example 2: regex replace /
str = str.replace(/\//g,'_');
Example 3: c# Replace Strings In C#
string odd = "1, 3, 5, 7, 9, 11, 13, 15, 17, 19";
Console.WriteLine($ "Original odd: {odd}");
string newOdd = odd.Replace(',', ':');
Console.WriteLine($ "New Odd: {newOdd}");
string authors = "Mahesh Beniwal, Neel Beniwal, Raj Beniwal, Dinesh Beniwal";
Console.WriteLine($ "Authors with last names: {authors}");
string firstNames = authors.Replace(" Beniwal", "");
Console.WriteLine($ "Authors without last names: {firstNames}");
Example 4: c# replace regex string
string pattern = @"\bwest\b";
string modifiedString = Regex.Replace(input, pattern, strReplacement, RegexOptions.IgnoreCase);