There is still a problem, but all of the above answers consider 12i or a2 to be real numbers when they shouldn't.
The following issues may resolve this issue.
var matches = Regex.Matches(input, @"(?:^|\s)\d+(?:\s|$)");
But this solution adds another problem :) This will capture the spaces around the integer. To solve this, we need to fix the value of the integer into the group:
MatchCollection matches = Regex.Matches(_originalText, @"(?:^|\s)(\d+)(?:\s|$)"); HashSet<string> uniqueNumbers = new HashSet<string>(); foreach (Match m in matches) { uniqueNumbers.Add(m.Groups[1].Value); }
Alexandros Biratsis
source share