0

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

0

2 Answers 2

2

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.

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

Comments

1

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;

2 Comments

If so I don`t understand when I use brackets
actually square brackets match a character class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.