github.com/samsalisbury/distribution@v2.2.1-0.20151123021722-54f974340220+incompatible/reference/regexp.go (about)

     1  package reference
     2  
     3  import "regexp"
     4  
     5  var (
     6  	// nameSubComponentRegexp defines the part of the name which must be
     7  	// begin and end with an alphanumeric character. These characters can
     8  	// be separated by any number of dashes.
     9  	nameSubComponentRegexp = regexp.MustCompile(`[a-z0-9]+(?:[-]+[a-z0-9]+)*`)
    10  
    11  	// nameComponentRegexp restricts registry path component names to
    12  	// start with at least one letter or number, with following parts able to
    13  	// be separated by one period, underscore or double underscore.
    14  	nameComponentRegexp = regexp.MustCompile(nameSubComponentRegexp.String() + `(?:(?:[._]|__)` + nameSubComponentRegexp.String() + `)*`)
    15  
    16  	nameRegexp = regexp.MustCompile(`(?:` + nameComponentRegexp.String() + `/)*` + nameComponentRegexp.String())
    17  
    18  	hostnameComponentRegexp = regexp.MustCompile(`(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])`)
    19  
    20  	// hostnameComponentRegexp restricts the registry hostname component of a repository name to
    21  	// start with a component as defined by hostnameRegexp and followed by an optional port.
    22  	hostnameRegexp = regexp.MustCompile(`(?:` + hostnameComponentRegexp.String() + `\.)*` + hostnameComponentRegexp.String() + `(?::[0-9]+)?`)
    23  
    24  	// TagRegexp matches valid tag names. From docker/docker:graph/tags.go.
    25  	TagRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`)
    26  
    27  	// anchoredTagRegexp matches valid tag names, anchored at the start and
    28  	// end of the matched string.
    29  	anchoredTagRegexp = regexp.MustCompile(`^` + TagRegexp.String() + `$`)
    30  
    31  	// DigestRegexp matches valid digests.
    32  	DigestRegexp = regexp.MustCompile(`[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}`)
    33  
    34  	// anchoredDigestRegexp matches valid digests, anchored at the start and
    35  	// end of the matched string.
    36  	anchoredDigestRegexp = regexp.MustCompile(`^` + DigestRegexp.String() + `$`)
    37  
    38  	// NameRegexp is the format for the name component of references. The
    39  	// regexp has capturing groups for the hostname and name part omitting
    40  	// the seperating forward slash from either.
    41  	NameRegexp = regexp.MustCompile(`(?:` + hostnameRegexp.String() + `/)?` + nameRegexp.String())
    42  
    43  	// ReferenceRegexp is the full supported format of a reference. The
    44  	// regexp has capturing groups for name, tag, and digest components.
    45  	ReferenceRegexp = regexp.MustCompile(`^((?:` + hostnameRegexp.String() + `/)?` + nameRegexp.String() + `)(?:[:](` + TagRegexp.String() + `))?(?:[@](` + DigestRegexp.String() + `))?$`)
    46  
    47  	// anchoredNameRegexp is used to parse a name value, capturing hostname
    48  	anchoredNameRegexp = regexp.MustCompile(`^(?:(` + hostnameRegexp.String() + `)/)?(` + nameRegexp.String() + `)$`)
    49  )