I want to match a sequence of alphabets and any number of digits seperated by a '-' . For example ABC-1
, ABC-12
, ABC-123
, ABC-1234
and so on..... I looked at an example Regex for numbers only and https://msdn.microsoft.com/en-us/library/3y21t6y4(v=vs.110).aspx .I got a code below.
var regex = new Regex($@"^[A - Z]{{{numberOfLettersBeforeHyphen}}}-\d+");
return regex.IsMatch(stringToMatch);
where numberOfLettersBeforeHyphen = 3
but it always return false for the above examples. Please point out where the mistake lies, which will help me to accomplish my goal. Thank you all