I am working on parsing the user provided input for a number which belongs to a specified pattern such as 199-234
where the
- first component is
1 - second component is
99 - third component is
234
The user would provide just the first few digits or the entire string. I intend to parse each of the components out. The reg-ex that I have come up with is -
Regex regex = new Regex(@"(?<first>\d)(?<second>\d{0,2})-?(?<third>\d{0,3})");
var groups = regex.Match(input);
If I provide the input 199 , the reg-ex pattern breaks them into 3 groups instead of the expected 2. Actual result is
- first component is
1 - second component is
9 - third component is
9
How do I ensure that the inputs get correctly matched in this case?