I have a log giving me messages that look like this
Error Message: \" Expected: 660m But was: 600m\" Error Message: \" Expected: 358m But was: 325m\" Error M
You may use a capturing group with a replacement backreference in the replacement pattern:
example = Regex.Replace(example, @"([0-9])[a-zA-Z]\b", "$1");
Note the \b
word boundary after the letter pattern, it is used to make sure the letter is at the end of the word.
See the regex demo. Result:
Pattern details
([0-9])
- Capturing group 1 (later referred to with $1
) matching any one digit[a-zA-Z]
- an ASCII letter\b
- a trailing word boundary