Regex does not match....how?

I’m confused.

string stuff = File.ReadAllText(@"AFilePathHere");
if (!stuff.Contains("###FLAG###"))
{
    stuff += "###FLAG###\r\n###FLAG###";
}
Regex regex = new("###FLAG###.*###FLAG###");
regex.Match(stuff);

The above yields no match. How? The string does have the text on the end of it. Regex101 says it matches. My eyes say it matches. C# says no.

Does C# need a modifier to tell it the match can occur over multiple lines, like PHP does?

See https://3v4l.org/HWaDB#v8.3.6

Would something like this work instead?

###FLAG###[\s\S]*?###FLAG###

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.