I'm looking for a regular expression to implement a search and replace method which identifies strings like "/Sample Text:" in a longer text (e.g. "This is a /Sample Text: in a sentence"), where 'Match whole word' and/or 'Match case' can be specified. I'm new to regular expressions. Thank you very much.
I tried something like below, but it is not what I expect:
var text = "This is a /Sample Text: in a sentence";
var oldValue = "/Sample Text:";
var newValue = "sample text";
var result = Regex.Replace(text, $"\\b{oldValue}{(char.IsPunctuation(newValue[newValue.Length - 1]) ? "(?!\\" + newValue[newValue.Length - 1] + ")" : string.Empty)}", newValue, RegexOptions.CultureInvariant);