c# regex replace string code example
Example 1: c sharp string replace
str = "Hello World!"
str.Replace('o', 'e');
Example 2: c# regex get matched string
Regex filter = new Regex(@"(\d+)");
foreach (var item in checkedListBox1.CheckedItems)
{
var match = filter.Match(item.ToString());
if (match.Success)
{
MessageBox.Show(match.Value);
}
}
Example 3: c# regex replace
Regex.Replace(
"input string", @"[a-zA-Z]+", "replace string"
);
Example 4: c# replace regex string
string pattern = @"\bwest\b";
string modifiedString = Regex.Replace(input, pattern, strReplacement, RegexOptions.IgnoreCase);