Reputation: 10153
I am implementing a method which need to find if the string corresponds to some pattern : I am using the following code :
if (Regex.IsMatch(str, @"^[\d]{3}00{\d]{4}$"))
{
return false;
}
return true;
And test it with this string "123003678"
It returns true...
I can`t figure out what is the problem there...Any thoughts?
Thanks
Upvotes: 0
Views: 97
Reputation: 1469
the use of brackets is a bit off in your string.
try this:
@"^\d{3}00\d{4}$"
in your regex example the second bracket starts with a { and ends with a ], which will screw things up.
Upvotes: 2
Reputation: 28413
you have messed up square bracket with curly braces
Try this
^[\d]{3}00[\d]{4}$
if (Regex.IsMatch(str, @"^[\d]{3}00[\d]{4}$"))
{
return false;
}
return true;
Upvotes: 1