I just wrote a regexp to do a basic syntax checking if a string is a valid math formular. I just define a group of valid chars and check if a string matches (I shortend the regex a little:
private static readonly String validFormuar = @"^[\d\+-\*\/]+$";
private static bool IsValidFormular(String value)
{
return Regex.IsMatch(value, validFormuar);
}
I will only allow digits, +, -, * and / in this example.
Because +,* and / are special chars in regular expressions I escaped them.
However this code throws an ArgumentException (translated from german)
"^[\d\+-\*\/]+$" is beeing analyzed - [x-y]-area in reversed Order.
If I double escape the *
private static readonly String validFormuar = @"^[\d\+-\\*\/]+$";
the result is as expected.
Is this a bug in the System.Text.RegularExpressions parser? Because I consider my first regexp as correct. If not, why do I have to escape the "*" twice?