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 \r
s \n
s, 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
Post a Comment