Reputation:
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?
Upvotes: 0
Views: 89
Reputation: 1275
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}$
Upvotes: 1
Reputation: 882751
Your arguments are switched. I.e., use:
Regex.IsMatch("babe", "[abcde]{1,16}")
instead,
Upvotes: 2