Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Regex find string between two strings with newLine

Here is my regex: Regex r = new Regex("start(.*?)end", RegexOptions.Multiline);

That means I want to get the stuff between "start" and "end". But the problem is that between start and end is a new line or \n and the regex doesn't return anything.

So how do I make regex find \n?

like image 550
AndroidXTr3meN Avatar asked May 20 '12 20:05

AndroidXTr3meN


1 Answers

The name of the Multiline option is misleading, as is the one of the correct option - Singleline:

Regex r = new Regex("start(.*?)end", RegexOptions.Singleline);

From MSDN, RegexOptions Enumeration:

Singleline - Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n).

like image 93
Oded Avatar answered Sep 28 '22 11:09

Oded