I am having an issue with identifying a multiple character digit in a string.
What I am attempting to do is check, from right to left, for the first digits for comparison.
My original regex:
Regex.Match(s, @"\d{3}", RegexOptions.RightToLeft);
This would match the first 3 digits it came across in any string. Eg:
- hello123 - Output: 123
- good234bye - Output: 234
- see-you-456-tomorrow - Output: 456
No worries. However, now we're not certain of the length the number might be, so we have changed the Regex to this:
Regex.Match(s, @"\d*", RegexOptions.RightToLeft);
This looks for the first string of digits, any length, and uses that. However, it returns an empty match if the number is not on the end of the string. Eg:
- hello12 - Output: 12
- good-bye-1234 - Output: 1234
- see-1-you-2-morrow - Output: Nothing
How can I look for the first x-length of digits in a string, from right to left and disregarding any non-digit characters, without it returning an empty match?