github.com/Aoi-hosizora/ahlib@v1.5.1-0.20230404072829-241b93cf91c7/xconstant/regexps/regexps.go (about) 1 package regexps 2 3 import ( 4 "regexp" 5 ) 6 7 // Regexps are referred from https://github.com/go-playground/validator/blob/v10.11.1/regexes.go. 8 9 const ( 10 alphaRegexString = "^[a-zA-Z]+$" 11 alphaNumericRegexString = "^[a-zA-Z0-9]+$" 12 alphaUnicodeRegexString = "^[\\p{L}]+$" 13 alphaUnicodeNumericRegexString = "^[\\p{L}\\p{N}]+$" 14 numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$" 15 numberRegexString = "^[0-9]+$" 16 hexadecimalRegexString = "^(0[xX])?[0-9a-fA-F]+$" 17 hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$" 18 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*\\)$" 19 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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{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]|\\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}])))\\.?$" 23 e164RegexString = "^\\+[1-9]?[0-9]{7,14}$" 24 base64RegexString = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" 25 base64URLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$" 26 iSBN10RegexString = "^(?:[0-9]{9}X|[0-9]{10})$" 27 iSBN13RegexString = "^(?:(?:97(?:8|9))[0-9]{10})$" 28 uUID3RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$" 29 uUID4RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" 30 uUID5RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" 31 uUIDRegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" 32 uUID3RFC4122RegexString = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-3[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" 33 uUID4RFC4122RegexString = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" 34 uUID5RFC4122RegexString = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-5[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$" 35 uUIDRFC4122RegexString = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" 36 uLIDRegexString = "^[A-HJKMNP-TV-Z0-9]{26}$" 37 md4RegexString = "^[0-9a-f]{32}$" 38 md5RegexString = "^[0-9a-f]{32}$" 39 sha256RegexString = "^[0-9a-f]{64}$" 40 sha384RegexString = "^[0-9a-f]{96}$" 41 sha512RegexString = "^[0-9a-f]{128}$" 42 ripemd128RegexString = "^[0-9a-f]{32}$" 43 ripemd160RegexString = "^[0-9a-f]{40}$" 44 tiger128RegexString = "^[0-9a-f]{32}$" 45 tiger160RegexString = "^[0-9a-f]{40}$" 46 tiger192RegexString = "^[0-9a-f]{48}$" 47 aSCIIRegexString = "^[\x00-\x7F]*$" 48 printableASCIIRegexString = "^[\x20-\x7E]*$" 49 multibyteRegexString = "[^\x00-\x7F]" 50 dataURIRegexString = `^data:((?:\w+\/(?:([^;]|;[^;]).)+)?)` 51 latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$" 52 longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" 53 sSNRegexString = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$` 54 hostnameRegexStringRFC952 = `^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$` // https://tools.ietf.org/html/rfc952 55 hostnameRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62}){1}(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?$` // accepts hostname starting with a digit https://tools.ietf.org/html/rfc1123 56 fqdnRegexStringRFC1123 = `^([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?$` // same as hostnameRegexStringRFC1123 but must contain a non numerical TLD (possibly ending with '.') 57 btcAddressRegexString = `^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$` // bitcoin address 58 btcAddressUpperRegexStringBech32 = `^BC1[02-9AC-HJ-NP-Z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32 59 btcAddressLowerRegexStringBech32 = `^bc1[02-9ac-hj-np-z]{7,76}$` // bitcoin bech32 address https://en.bitcoin.it/wiki/Bech32 60 ethAddressRegexString = `^0x[0-9a-fA-F]{40}$` 61 ethAddressUpperRegexString = `^0x[0-9A-F]{40}$` 62 ethAddressLowerRegexString = `^0x[0-9a-f]{40}$` 63 uRLEncodedRegexString = `^(?:[^%]|%[0-9A-Fa-f]{2})*$` 64 hTMLEncodedRegexString = `&#[x]?([0-9a-fA-F]{2})|(>)|(<)|(")|(&)+[;]?` 65 hTMLRegexString = `<[/]?([a-zA-Z]+).*?>` 66 jWTRegexString = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$" 67 splitParamsRegexString = `'[^']*'|\S+` 68 bicRegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$` 69 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/ 70 dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9]){0,62}$" 71 ) 72 73 var ( 74 AlphaRegex = regexp.MustCompile(alphaRegexString) 75 AlphaNumericRegex = regexp.MustCompile(alphaNumericRegexString) 76 AlphaUnicodeRegex = regexp.MustCompile(alphaUnicodeRegexString) 77 AlphaUnicodeNumericRegex = regexp.MustCompile(alphaUnicodeNumericRegexString) 78 NumericRegex = regexp.MustCompile(numericRegexString) 79 NumberRegex = regexp.MustCompile(numberRegexString) 80 HexadecimalRegex = regexp.MustCompile(hexadecimalRegexString) 81 HexColorRegex = regexp.MustCompile(hexColorRegexString) 82 RgbRegex = regexp.MustCompile(rgbRegexString) 83 RgbaRegex = regexp.MustCompile(rgbaRegexString) 84 HslRegex = regexp.MustCompile(hslRegexString) 85 HslaRegex = regexp.MustCompile(hslaRegexString) 86 E164Regex = regexp.MustCompile(e164RegexString) 87 EmailRegex = regexp.MustCompile(emailRegexString) 88 Base64Regex = regexp.MustCompile(base64RegexString) 89 Base64URLRegex = regexp.MustCompile(base64URLRegexString) 90 ISBN10Regex = regexp.MustCompile(iSBN10RegexString) 91 ISBN13Regex = regexp.MustCompile(iSBN13RegexString) 92 UUID3Regex = regexp.MustCompile(uUID3RegexString) 93 UUID4Regex = regexp.MustCompile(uUID4RegexString) 94 UUID5Regex = regexp.MustCompile(uUID5RegexString) 95 UUIDRegex = regexp.MustCompile(uUIDRegexString) 96 UUID3RFC4122Regex = regexp.MustCompile(uUID3RFC4122RegexString) 97 UUID4RFC4122Regex = regexp.MustCompile(uUID4RFC4122RegexString) 98 UUID5RFC4122Regex = regexp.MustCompile(uUID5RFC4122RegexString) 99 UUIDRFC4122Regex = regexp.MustCompile(uUIDRFC4122RegexString) 100 ULIDRegex = regexp.MustCompile(uLIDRegexString) 101 Md4Regex = regexp.MustCompile(md4RegexString) 102 Md5Regex = regexp.MustCompile(md5RegexString) 103 Sha256Regex = regexp.MustCompile(sha256RegexString) 104 Sha384Regex = regexp.MustCompile(sha384RegexString) 105 Sha512Regex = regexp.MustCompile(sha512RegexString) 106 Ripemd128Regex = regexp.MustCompile(ripemd128RegexString) 107 Ripemd160Regex = regexp.MustCompile(ripemd160RegexString) 108 Tiger128Regex = regexp.MustCompile(tiger128RegexString) 109 Tiger160Regex = regexp.MustCompile(tiger160RegexString) 110 Tiger192Regex = regexp.MustCompile(tiger192RegexString) 111 ASCIIRegex = regexp.MustCompile(aSCIIRegexString) 112 PrintableASCIIRegex = regexp.MustCompile(printableASCIIRegexString) 113 MultibyteRegex = regexp.MustCompile(multibyteRegexString) 114 DataURIRegex = regexp.MustCompile(dataURIRegexString) 115 LatitudeRegex = regexp.MustCompile(latitudeRegexString) 116 LongitudeRegex = regexp.MustCompile(longitudeRegexString) 117 SSNRegex = regexp.MustCompile(sSNRegexString) 118 HostnameRegexRFC952 = regexp.MustCompile(hostnameRegexStringRFC952) 119 HostnameRegexRFC1123 = regexp.MustCompile(hostnameRegexStringRFC1123) 120 FqdnRegexRFC1123 = regexp.MustCompile(fqdnRegexStringRFC1123) 121 BtcAddressRegex = regexp.MustCompile(btcAddressRegexString) 122 BtcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32) 123 BtcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32) 124 EthAddressRegex = regexp.MustCompile(ethAddressRegexString) 125 EthAddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString) 126 EthAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString) 127 URLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString) 128 HTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString) 129 HTMLRegex = regexp.MustCompile(hTMLRegexString) 130 JWTRegex = regexp.MustCompile(jWTRegexString) 131 SplitParamsRegex = regexp.MustCompile(splitParamsRegexString) 132 BicRegex = regexp.MustCompile(bicRegexString) 133 SemverRegex = regexp.MustCompile(semverRegexString) 134 DnsRegexRFC1035Label = regexp.MustCompile(dnsRegexStringRFC1035Label) 135 )