Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(?im)([a-z0-9\-\_.]+)?(\/[a-z0-9\-.]+)?(:[\w\.\-\_]+)?$
/
g

Description

Used by Zarf to swap the registry domain/port part an image url without needed the docker libraries. usage in go:

// SwapHost Perform base url replacement and adds a sha1sum of the original url to the end of the src
func SwapHost(src string, targetHost string) (string, error) {
	targetImage, err := getTargetImageFromURL(src)
	return targetHost + "/" + targetImage, err
}
Submitted by Jonathan Perry - 2 years ago