Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is any character (including new line) pattern in regex?

Tags:

c#

regex

Does regex have a pattern that match any characters including new line in regex? The dot pattern match any characters but isn't including new line, (currently, I'm using [^~] because the ~ character is rarely use).

Edit: I'm using regex with C# language.

like image 522
Bình Nguyên Avatar asked May 20 '14 05:05

Bình Nguyên


1 Answers

Using #C, you can use the RegexOptions.Singleline compiler flag.

Use single-line mode, where (.) matches every character (instead of every character except \n)

And instead of the RegexOptions.Singleline compiler flag, you can get the same effect by placing an inline modifier at the very beginning of your regular expression.

Regex.Match(input, @"(?s)foo.*bar");
like image 110
hwnd Avatar answered Sep 18 '22 18:09

hwnd