0

I'm trying to match values by using regular expression, but I'm unable to get why following program returning me false as output.

Regex validateInputString = new Regex("^(\\d)*([a-z[A-Z]])+$");
    Console.WriteLine(validateInputString.IsMatch("343sdf"));

Could anyone please tell me?

2 Answers 2

1

[a-z[A-Z]] does not look very correct. Do you mean [a-zA-Z] ?

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

Comments

0

You cannot have character classes within character classes. If you want to match either of the letters a-z and A-Z just use one character class [a-zA-z]. E.g.

Regex validateInputString = new Regex("^(\\d)*([a-zA-Z])+$");
Console.WriteLine(validateInputString.IsMatch("343sdf"));

The code above prints True.

Comments

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.