YAKOVM
YAKOVM

Reputation: 10153

Regex matching the pattern with string

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

Answers (2)

martijn
martijn

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

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

you have messed up square bracket with curly braces

Try this

^[\d]{3}00[\d]{4}$

Regex Demo

if (Regex.IsMatch(str, @"^[\d]{3}00[\d]{4}$"))
{
      return false;
}
return true;

Upvotes: 1

Related Questions