In C#, I write the following string to a string variable, carriage return and all:
asdfasdfasdf asdfas<test>asdfasdf asdfasdf<test>asdfasdf
In Notepad2, I use this regular expression:
<test>.*<test>
It selects this text as expected:
<test>asdfasdf asdfasdf<test>
However, when I do this in C#:
System.Text.RegularExpressions.Regex.Replace(s, "<test>.*<test>", string.Empty);
It doesn't remove the string. However, when I run this code on a string without any carriage returns, it does work.
So what I am looking for is a regex that will match ANY character, regardless whether or not it is a control code or a regular character.
You forgot to specify that the Regex operation (specifically, the .
operator) should match all characters (not all characters except \n):
System.Text.RegularExpressions.Regex.Replace(s, "<test>.*<test>", string.Empty, RegexOptions.Singleline);
All you needed to add was RegexOptions.Singleline
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With