@@ -5,6 +5,58 @@ namespace Microsoft.ComponentDetection.Common
55{
66 public class DockerRegex
77 {
8+ public static Regex AlphaNumericRegexp = new Regex ( "[a-z0-9]+" ) ;
9+ public static Regex SeparatorRegexp = new Regex ( "(?:[._]|__|[-]*)" ) ;
10+
11+ public static Regex DomainComponentRegexp = new Regex ( "(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])" ) ;
12+ public static Regex TagRegexp = new Regex ( @"[\w][\w.-]{0,127}" ) ;
13+ public static Regex DigestRegexp = new Regex ( "[a-zA-Z][a-zA-Z0-9]*(?:[-_+.][a-zA-Z][a-zA-Z0-9]*)*[:][a-fA-F0-9]{32,}" ) ;
14+ public static Regex IdentifierRegexp = new Regex ( "[a-f0-9]{64}" ) ;
15+
16+ public static Regex NameComponentRegexp = Expression (
17+ AlphaNumericRegexp ,
18+ Optional ( Repeated ( SeparatorRegexp , AlphaNumericRegexp ) ) ) ;
19+
20+ public static Regex DomainRegexp = Expression (
21+ DomainComponentRegexp ,
22+ Optional (
23+ Repeated (
24+ new Regex ( @"\." ) ,
25+ DomainComponentRegexp ) ) ,
26+ Optional (
27+ new Regex ( ":" ) ,
28+ new Regex ( "[0-9]+" ) ) ) ;
29+
30+ public static Regex AnchoredDigestRegexp = Anchored ( DigestRegexp ) ;
31+
32+ public static Regex NameRegexp = Expression (
33+ Optional (
34+ DomainRegexp ,
35+ new Regex ( @"\/" ) ) ,
36+ NameComponentRegexp ,
37+ Optional (
38+ Repeated (
39+ new Regex ( @"\/" ) ,
40+ NameComponentRegexp ) ) ) ;
41+
42+ public static Regex AnchoredNameRegexp = Anchored (
43+ Optional (
44+ Capture ( DomainRegexp ) ,
45+ new Regex ( @"\/" ) ) ,
46+ Capture (
47+ NameComponentRegexp ,
48+ Optional (
49+ Repeated (
50+ new Regex ( @"\/" ) ,
51+ NameComponentRegexp ) ) ) ) ;
52+
53+ public static Regex ReferenceRegexp = Anchored (
54+ Capture ( NameRegexp ) ,
55+ Optional ( new Regex ( ":" ) , Capture ( TagRegexp ) ) ,
56+ Optional ( new Regex ( "@" ) , Capture ( DigestRegexp ) ) ) ;
57+
58+ public static Regex AnchoredIdentifierRegexp = Anchored ( IdentifierRegexp ) ;
59+
860 /// <summary>
961 /// expression defines a full expression, where each regular expression must follow the previous.
1062 /// </summary>
@@ -64,57 +116,5 @@ public static Regex Capture(params Regex[] regexps)
64116 {
65117 return new Regex ( $ "({ Expression ( regexps ) . ToString ( ) } )") ;
66118 }
67-
68- public static Regex AlphaNumericRegexp = new Regex ( "[a-z0-9]+" ) ;
69- public static Regex SeparatorRegexp = new Regex ( "(?:[._]|__|[-]*)" ) ;
70-
71- public static Regex DomainComponentRegexp = new Regex ( "(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])" ) ;
72- public static Regex TagRegexp = new Regex ( @"[\w][\w.-]{0,127}" ) ;
73- public static Regex DigestRegexp = new Regex ( "[a-zA-Z][a-zA-Z0-9]*(?:[-_+.][a-zA-Z][a-zA-Z0-9]*)*[:][a-fA-F0-9]{32,}" ) ;
74- public static Regex IdentifierRegexp = new Regex ( "[a-f0-9]{64}" ) ;
75-
76- public static Regex NameComponentRegexp = Expression (
77- AlphaNumericRegexp ,
78- Optional ( Repeated ( SeparatorRegexp , AlphaNumericRegexp ) ) ) ;
79-
80- public static Regex DomainRegexp = Expression (
81- DomainComponentRegexp ,
82- Optional (
83- Repeated (
84- new Regex ( @"\." ) ,
85- DomainComponentRegexp ) ) ,
86- Optional (
87- new Regex ( ":" ) ,
88- new Regex ( "[0-9]+" ) ) ) ;
89-
90- public static Regex AnchoredDigestRegexp = Anchored ( DigestRegexp ) ;
91-
92- public static Regex NameRegexp = Expression (
93- Optional (
94- DomainRegexp ,
95- new Regex ( @"\/" ) ) ,
96- NameComponentRegexp ,
97- Optional (
98- Repeated (
99- new Regex ( @"\/" ) ,
100- NameComponentRegexp ) ) ) ;
101-
102- public static Regex AnchoredNameRegexp = Anchored (
103- Optional (
104- Capture ( DomainRegexp ) ,
105- new Regex ( @"\/" ) ) ,
106- Capture (
107- NameComponentRegexp ,
108- Optional (
109- Repeated (
110- new Regex ( @"\/" ) ,
111- NameComponentRegexp ) ) ) ) ;
112-
113- public static Regex ReferenceRegexp = Anchored (
114- Capture ( NameRegexp ) ,
115- Optional ( new Regex ( ":" ) , Capture ( TagRegexp ) ) ,
116- Optional ( new Regex ( "@" ) , Capture ( DigestRegexp ) ) ) ;
117-
118- public static Regex AnchoredIdentifierRegexp = Anchored ( IdentifierRegexp ) ;
119119 }
120120}
0 commit comments