0

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 Answers 2

2

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

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

instead,

Sign up to request clarification or add additional context in comments.

Comments

1

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}$

Comments