A
A
Atlant1Q2018-02-27 17:10:30
.NET
Atlant1Q, 2018-02-27 17:10:30

Why doesn't the regex work?

string pattern = @"\d{3}(-XX-)\d{2}(/)(?:\d{5}|\d{7})";
            string value1 = @"111-XX-99/12345";
            string value2 = @"111-XX-99/1234567";
            var rez1 = Regex.IsMatch(value1, pattern);
            var rez2 = Regex.IsMatch(value2, pattern);

IsMatch returns true, but if, for example, you write value = @"1111-XX-99/12345678"; it still returns true. How can I fix the expression so that it only skips 5 or 7 digits after the / ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-02-27
@Atlant1Q

try
\d{3}(-XX-)\d{2}(/)(?:\d{5}|\d{7})\b

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question