treating \r as \n in c# regex -


i have c# function finds patters of text in side input , processing. (i using 3.5 version of .net framework)

public void func(string s) {     regex r = new regex("^\s*pattern\s*$", regexoptions.multiline | regexoptions.explicitcapture );     match m = r.match(s);     //do m } 

a use of function might this

string s = "pattern \n pattern \n non-pattern"; func(s); 

however, finding input looking more this

string s = "pattern \r pattern \r non-pattern" func(s); 

and not being matched. there way have \r treated \n within regex? figure replace \rs \ns, hoping minimize operations if regex @ once.

unfortunatly, when have run in similar situations situation found works 2 passes regex (like hoping avoid), first 1 normalizes line endings 2nd 1 can search normal, there no way multiline trigger on /r find.

public void func(string s) {     s = regex.replace(s, @"(\r\n|\n\r|\n|\r)", "\r\n");     regex r = new regex("^\s*pattern\s*$", regexoptions.multiline | regexoptions.explicitcapture );     match m = r.match(s);     //do m } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -