-1

With this code, isMatch is false.

var input = "12312345023";
var isMatch = Regex.IsMatch(@"^\d{6,}", input);

And if input = "", isMatch is true. Not sure why it seems to be opposite of what it should be.

If I try the same pattern and input here it works as expected. But when I start a new console app with just that code, isMatch is not correct.

0

1 Answer 1

3

MSDN says:

public static bool IsMatch(
          string input,
          string pattern
)

Since your parameters are swapped, your pattern is empty. The result will always be true. You need to swap your parameters to get a correct result:

var isMatch = Regex.IsMatch(input, @"^\d{6,}");
Sign up to request clarification or add additional context in comments.

1 Comment

doh! of course! thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.