c# - Regex patterns to distinguish four digit numbers -
hi have c# application accepts 4 digit extension number , sets mask it. have situation 2 different masks need applied depending on number.
first: if number starts 47 or 5 return mask a. second: if number starts 6 or 55 return mask b.
so setup regex way , not sure why getting set wrong.
//here trying say, start 47 or 5 next 3 digits taking number match first = regex.match(num, "^(47|(5[0123456789]{3}))"); //anything start 6 or 55 next 2 digits taking numbers 0-5 match secong = regex.match(num, "(6|55[123450]{2})");
if give use above input num=5850 or num=5511 true both 5850 should use mask , 5511 should use mask b
how fix this??
thanks!
these should you.
this matches 4 digit number starting 47 or 5, excluding 5 second digit.
^(47|5([0-4]|[6-9]))\d{2}$
this matches 4 digit number starting 6 or 55.
^(6\d|55)\d{2}$
Comments
Post a Comment