using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?!.*\-{2}.*)(?!.*\+{2}.*)(?!.*\.{2}.*)(?P<major>(?!0)(\d*)|([0[^\d]))((?>\.)(?P<minor>\g<1>))\.(?P<patch>\g<minor>)(?![\+\-][^a-zA-Z0-9])(\g<2>(\-(?P<release>[a-zA-Z0-9\.-]+)))?(\+(?P<build>\g<9>))?$";
string input = @"#good
0.1.2
1.2.3
10.20.3
1.2.3-alpha.23-pre
12.12.3-123.hexagon+dontmakemecompileplea.se
1.2.3-alpha-dev.51-something+mybuild-1-4-1975-clang
4.3.22+mybuild
4.1.405+hexa.13331-objectfiles
# bad
01.2.3
1.02.3
2.3.04
a.1.1
1.a.1
1.1.a
1.2.3-rele..ase+build
1.2.3-release-something+..build
1.2.3-rele--ase+build
1.2.3-release-something+--build
1.2.3-release++build
1.2.3+-release-something-build";
RegexOptions options = RegexOptions.Multiline;
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