http urls monitor.

regexes.go 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package validator
  2. import "regexp"
  3. const (
  4. alphaRegexString = "^[a-zA-Z]+$"
  5. alphaNumericRegexString = "^[a-zA-Z0-9]+$"
  6. numericRegexString = "^[-+]?[0-9]+(?:\\.[0-9]+)?$"
  7. numberRegexString = "^[0-9]+$"
  8. hexadecimalRegexString = "^[0-9a-fA-F]+$"
  9. hexcolorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
  10. 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*\\)$"
  11. 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?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$"
  12. hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-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\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}])))\\.?$"
  15. base64RegexString = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
  16. iSBN10RegexString = "^(?:[0-9]{9}X|[0-9]{10})$"
  17. iSBN13RegexString = "^(?:(?:97(?:8|9))[0-9]{10})$"
  18. uUID3RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$"
  19. uUID4RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
  20. uUID5RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
  21. uUIDRegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
  22. aSCIIRegexString = "^[\x00-\x7F]*$"
  23. printableASCIIRegexString = "^[\x20-\x7E]*$"
  24. multibyteRegexString = "[^\x00-\x7F]"
  25. dataURIRegexString = "^data:.+\\/(.+);base64$"
  26. latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$"
  27. longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$"
  28. sSNRegexString = `^\d{3}[- ]?\d{2}[- ]?\d{4}$`
  29. )
  30. var (
  31. alphaRegex = regexp.MustCompile(alphaRegexString)
  32. alphaNumericRegex = regexp.MustCompile(alphaNumericRegexString)
  33. numericRegex = regexp.MustCompile(numericRegexString)
  34. numberRegex = regexp.MustCompile(numberRegexString)
  35. hexadecimalRegex = regexp.MustCompile(hexadecimalRegexString)
  36. hexcolorRegex = regexp.MustCompile(hexcolorRegexString)
  37. rgbRegex = regexp.MustCompile(rgbRegexString)
  38. rgbaRegex = regexp.MustCompile(rgbaRegexString)
  39. hslRegex = regexp.MustCompile(hslRegexString)
  40. hslaRegex = regexp.MustCompile(hslaRegexString)
  41. emailRegex = regexp.MustCompile(emailRegexString)
  42. base64Regex = regexp.MustCompile(base64RegexString)
  43. iSBN10Regex = regexp.MustCompile(iSBN10RegexString)
  44. iSBN13Regex = regexp.MustCompile(iSBN13RegexString)
  45. uUID3Regex = regexp.MustCompile(uUID3RegexString)
  46. uUID4Regex = regexp.MustCompile(uUID4RegexString)
  47. uUID5Regex = regexp.MustCompile(uUID5RegexString)
  48. uUIDRegex = regexp.MustCompile(uUIDRegexString)
  49. aSCIIRegex = regexp.MustCompile(aSCIIRegexString)
  50. printableASCIIRegex = regexp.MustCompile(printableASCIIRegexString)
  51. multibyteRegex = regexp.MustCompile(multibyteRegexString)
  52. dataURIRegex = regexp.MustCompile(dataURIRegexString)
  53. latitudeRegex = regexp.MustCompile(latitudeRegexString)
  54. longitudeRegex = regexp.MustCompile(longitudeRegexString)
  55. sSNRegex = regexp.MustCompile(sSNRegexString)
  56. )