HighTechTalks DotNet Forums  

RegexOptions.Multiline?

CSharp microsoft.public.dotnet.languages.csharp


Discuss RegexOptions.Multiline? in the CSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Valery
 
Posts: n/a

Default RegexOptions.Multiline? - 07-10-2010 , 07:48 AM






The following code unexpectedly produces mismatch:

string s = "def" + System.Environment.NewLine + "ghi";
bool b = Regex.IsMatch(s, "^def$", RegexOptions.Multiline);

whereas

string s = "abc" + System.Environment.NewLine + "def";
bool b = Regex.IsMatch(s, "^def$", RegexOptions.Multiline);

produces true as expected.

What's wrong here?

Cheers, Valery

Reply With Quote
  #2  
Old   
Arne Vajhøj
 
Posts: n/a

Default Re: RegexOptions.Multiline? - 07-10-2010 , 09:14 AM






On 10-07-2010 08:48, Valery wrote:
Quote:
string s = "def" + System.Environment.NewLine + "ghi";
bool b = Regex.IsMatch(s, "^def$", RegexOptions.Multiline);

whereas

string s = "abc" + System.Environment.NewLine + "def";
bool b = Regex.IsMatch(s, "^def$", RegexOptions.Multiline);
Use:

string s = "def\nghi";

and:

string s = "abc\ndef";

then it seems to work.

I think it is a bit weird to use *nix semantics in .NET,
but that seems to be how it is.

Docs says:

<quote>
$

The match must occur at the end of the string or before \n at the end of
the line or string.
</quote>

So it is documented.

Arne

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.