C # Regex Pattern Conundrum

I have a regex that I checked in three separate sources, successfully matching the right text.

But, when I use regex in my code. This does not give a match. I used another regex with this code, and they led to the desired matches. I am at a loss ...

string SampleText = "starttexthere\r\nothertexthereendtexthere";
string RegexPattern = "(?<=starttexthere)(.*?)(?=endtexthere)";
Regex FindRegex = new Regex(@RegexPattern);
Match m = FindRegex.Match(SampleText);

I do not know if the problem is my regular expression or my code.

+5
source share
2 answers

, \r\n, , . , option . \n ( )

 Regex FindRegex = new Regex(@RegexPattern, RegexOptions.Multiline | RegexOptions.Singleline);
+7

RegexOptions.Multiline.

, , (\r\ \n).

, : (?<=starttexthere)[\w\r\n]+(?=endtexthere), .

-: http://ideone.com/ZXgKar

0

All Articles