c# - Why "[" gets matched by [a-zA-Z] -


this question has answer here:

regex oregex = new regex(@"test[a-za-z]"); string st = @"this test1 , testa , test[abc] testb , test(xyz) again."; foreach(match match in oregex.matches(st)) {      console.writeline(match.value); } 

output:

testa

test[

testb

question: why test[ in output? character class [a-za-z] supposed match alpha characters through z , through z.

you have typo in regex. [a-za-z] should [a-za-z].

the character [ between a , z characters.


Comments