using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^
[-−]? #dash or minus
(?: [1-9]\d{0,2}
(?:,\d{3})*
| 0
)
(?:\.\d+)?
$";
string input = @"Valid
0
0.00
0.1
0.01
0.001
0.0001
0.00001
1.0
1
8
9
10
11
12
20
21
99
100
101
111
999
1,000
1,001
2,100
9,999
10,000
999,999
1,000,000
1,000,001
Invalid
00
0,1
0,001
0.0000 1
0,100
9999
,111
999,9999,999";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx