tags:

views:

60

answers:

2

How comes this writes False?

Console.Write(Regex.IsMatch("[abcde]{1,16}", "babe"));

What's wrong with my regex? Doesn't that regex roughly translate to: contains between 1 and 16 characters, a through e?

+2  A: 

Your arguments are switched. I.e., use:

Regex.IsMatch("babe", "[abcde]{1,16}")

instead,

Alex Martelli
ah! Good catch.
Nick Riggs
+1  A: 

That's going to match any of the characters in "babe" that fall between a and e. So for example, "babez" would match as "babe". I get the sense you want treat it as a string match. Try:

[a-e]{1,16}$
Nick Riggs