Reputation: 97
I need to write the regular expression to fit a specific code pattern: the string to match has 18 integer characters and I need to check if in the first position there is 0 and in the second one 8 or 9. I wrote this expression, but it doesn't work:
Regex regex = new Regex(@"^(.{0}[0]{1}[8,9])(^\d{18}$)");
string compare = "082008014385161873";
if (regex.IsMatch(compare))
{
//true
}
Anyone can help me?
Upvotes: 1
Views: 1136
Reputation:
Try this regular expression. It does the following:
.
^0[89]\d{16}$
Upvotes: 1
Reputation: 369374
Use following regular expression:
^0[89]\d{16}$
Alternative using positive lookahead assertion:
^(?=0[89])\d{18}$
Upvotes: 1