You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
7.0 KiB
79 lines
7.0 KiB
package is
|
|
|
|
import "regexp"
|
|
|
|
const (
|
|
alphaRegexString = "^[a-zA-Z]+$"
|
|
alphaNumericRegexString = "^[a-zA-Z0-9]+$"
|
|
alphaUnicodeRegexString = "^[\\p{L}]+$"
|
|
alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$"
|
|
numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
|
|
numberRegexString = "^[0-9]+$"
|
|
hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$"
|
|
hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$"
|
|
rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$"
|
|
rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|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}-\\x{FFEF}])|(?:(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(?:(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])(?:[a-zA-Z]|\\d|-|\\.|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*(?:[a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
|
|
e164RegexString = "^\\+[1-9]?[0-9]{7,14}$"
|
|
phoneNumberRegexString = "^(\\+?86)?1[0-9]{10}$"
|
|
base64RegexString = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
|
|
base64URLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$"
|
|
uUID3RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
|
|
uUID4RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
uUID5RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
uUIDRegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
|
|
uLIDRegexString = "^[A-HJKMNP-TV-Z0-9]{26}$"
|
|
md4RegexString = "^[0-9a-f]{32}$"
|
|
md5RegexString = "^[0-9a-f]{32}$"
|
|
sha256RegexString = "^[0-9a-f]{64}$"
|
|
sha384RegexString = "^[0-9a-f]{96}$"
|
|
sha512RegexString = "^[0-9a-f]{128}$"
|
|
aSCIIRegexString = "^[\x00-\x7F]*$"
|
|
latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
|
|
longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
|
|
uRLEncodedRegexString = `^(?:[^%]|%[0-9A-Fa-f]{2})*$`
|
|
hTMLEncodedRegexString = `&#[x]?([0-9a-fA-F]{2})|(>)|(<)|(")|(&)+[;]?`
|
|
hTMLRegexString = `<[/]?([a-zA-Z]+).*?>`
|
|
jWTRegexString = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$"
|
|
semverRegexString = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` // numbered capture groups https://semver.org/
|
|
)
|
|
|
|
var (
|
|
alphaRegex = regexp.MustCompile(alphaRegexString)
|
|
alphaNumericRegex = regexp.MustCompile(alphaNumericRegexString)
|
|
alphaUnicodeRegex = regexp.MustCompile(alphaUnicodeRegexString)
|
|
alphaUnicodeNumericRegex = regexp.MustCompile(alphaUnicodeNumericRegexString)
|
|
numericRegex = regexp.MustCompile(numericRegexString)
|
|
numberRegex = regexp.MustCompile(numberRegexString)
|
|
hexadecimalRegex = regexp.MustCompile(hexadecimalRegexString)
|
|
hexColorRegex = regexp.MustCompile(hexColorRegexString)
|
|
rgbRegex = regexp.MustCompile(rgbRegexString)
|
|
rgbaRegex = regexp.MustCompile(rgbaRegexString)
|
|
hslRegex = regexp.MustCompile(hslRegexString)
|
|
hslaRegex = regexp.MustCompile(hslaRegexString)
|
|
e164Regex = regexp.MustCompile(e164RegexString)
|
|
phoneNumberRegex = regexp.MustCompile(phoneNumberRegexString)
|
|
emailRegex = regexp.MustCompile(emailRegexString)
|
|
base64Regex = regexp.MustCompile(base64RegexString)
|
|
base64URLRegex = regexp.MustCompile(base64URLRegexString)
|
|
uUID3Regex = regexp.MustCompile(uUID3RegexString)
|
|
uUID4Regex = regexp.MustCompile(uUID4RegexString)
|
|
uUID5Regex = regexp.MustCompile(uUID5RegexString)
|
|
uUIDRegex = regexp.MustCompile(uUIDRegexString)
|
|
uLIDRegex = regexp.MustCompile(uLIDRegexString)
|
|
md4Regex = regexp.MustCompile(md4RegexString)
|
|
md5Regex = regexp.MustCompile(md5RegexString)
|
|
sha256Regex = regexp.MustCompile(sha256RegexString)
|
|
sha384Regex = regexp.MustCompile(sha384RegexString)
|
|
sha512Regex = regexp.MustCompile(sha512RegexString)
|
|
aSCIIRegex = regexp.MustCompile(aSCIIRegexString)
|
|
latitudeRegex = regexp.MustCompile(latitudeRegexString)
|
|
longitudeRegex = regexp.MustCompile(longitudeRegexString)
|
|
uRLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString)
|
|
hTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString)
|
|
hTMLRegex = regexp.MustCompile(hTMLRegexString)
|
|
jWTRegex = regexp.MustCompile(jWTRegexString)
|
|
semverRegex = regexp.MustCompile(semverRegexString)
|
|
)
|
|
|