c# - Regex expression error -


currently dont want below string passed regex

refer mtf#y2015-19555 

regex

(.)\\1{2,} 

image1

the photo attached appeared impossible passed regex, program happened string matched regex, want know happened it

image2

i think problem is, regex-pattern differently seen regex-tester , .net framework. when using pattern in code, have keep in mind, string checked escape characters.

while regex-tester gets (.)\\1{2,}, .net framework regex gets (.)\1{2,} because "\\" becomes \. fix changing pattern string pattern = "(.)\\\\1{2,}"; or disable escape characters using string pattern = @"(.)\\1{2,}";.

you can see difference considering pattern \w.

regex.match("\w", myteststring); 

this cause compiler error because "\w" contains unknown escape sequence (the string evaluated @ development time). fix error, i'm adding @ in front of string , compiler satisfied.

regex.match(@"\w", myteststring); 

in case, don't error because "\\" still valid string. experienced,

regex.match("\\", myteststring); regex.match(@"\\",myteststring); 

may lead different results.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -