I am trying to decipher a regex file used for form validation and I have to list out all the acceptable Characters and Character counts for each field and I have been given a regex file to do this.
I have worked out some of the rules, but I am not very good with regex and want to ensure I have it all correct.
Here is the regex:
{
"lastName": "^(?=.{1,30}$)[A-Za-z`\\u0027\\- ]*$",
"country": "^(AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW)$",
"city": "^(?=^.{1,64}$)[A-Za-z \\-/&#,]*$",
"postalCode": "^[0-9]{5}(?:-[0-9]{4})?$",
"companyName": "^(?=.{0,45}$)[\\]A-Za-z0-9 $\\^~`<>+-_=\\u0027\\[#\\$%&*\\(\\)\\.,\\?\\\\]*$",
"customFieldEmail": "(?=^.{1,50}$)(^[a-zA-Z0-9!#$%&\\u0027*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&\\u0027*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+([a-zA-Z]{2,})$)",
"tributeFrom": "^(?=.{1,60}$)[A-Za-z0-9!#$%&\\u0027*+/=?^_`\\u0027{|}~\\\\\\-@. ]*$",
"tributeEmailSubject": "^(?=.{1,50}$)[A-Za-z0-9!#$%&\\u0027*+/=?^_`{|}~\\\\\\-@. ]*$",
"tributeMessage": "^([\\S\\s]{1,250})$",
"tributeMailMessage": "^([\\S\\s]{1,80})$",
"state": "^(?:A[KLRZAPES]|C[AOT]|D[CE]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])*$",
"email": "(?=^.{1,50}$)(^[a-zA-Z0-9!#$%&\\u0027*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&\\u0027*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+([a-zA-Z]{2,})$)",
"cvv3": "^[0-9]{3,3}$",
"cvv4": "^[0-9]{4,4}$",
"cvv": "^[0-9]{3,4}$",
"tributeName": "^(?=.{1,60}$)[\\]A-Za-z0-9 $\\^~`<>+-_=\\u0027!@\\[#\\$%&*\\(\\)\\.,\\?\\\\]*$",
"passwordStrong": "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[\\\\.\\\\,\\\\;\\\\:\\\\@\\\\№\\\\#\\\\$\\\\%\\\\&\\\\*\\\\+\\\\=\\\\?\\\\!\\\\^\\\\\\\\\\/\\\\|\\\\-\\\\_\\\\~\\\\\"\\\\'\\\\`\\\\(\\\\)\\\\{\\\\}\\\\[\\\\]])(?=\\S+$).{12,64}$",
"address2": "^[A-Za-z0-9 \\-/&#,.]{0,128}$",
"address1": "^[A-Za-z0-9 \\-/&#,.]{1,128}$",
"billCity": "^(?=^.{1,50}$)[A-Za-z \\-/&#,]*$",
"firstName": "^(?=.{1,30}$)[A-Za-z`\\u0027\\- ]*$",
"phoneNumber": "^[0-9]{1,10}$",
"customFieldFreeForm": ".*$",
"billAddress2": "^[A-Za-z0-9 \\-/&#,.]{0,60}$",
"billAddress1": "^[A-Za-z0-9 \\-/&#,.]{1,60}$",
"creditCard": "^(?:4[0-9]{12}(?:[0-9]{3})?|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\\d{3})\\d{11})$",
"donationAmount": "^(?=[1-9])\\d{1,5}(?:\\.\\d{2,2})?$",
"passwordWeak": "^(?!(.)\\1{5})(.){6,64}$",
"passwordGood": "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[\\\\.\\\\,\\\\;\\\\:\\\\@\\\\№\\\\#\\\\$\\\\%\\\\&\\\\*\\\\+\\\\=\\\\?\\\\!\\\\^\\\\\\\\\\/\\\\|\\\\-\\\\_\\\\~\\\\\"\\\\'\\\\`\\\\(\\\\)\\\\{\\\\}\\\\[\\\\]])(?=\\S+$).{8,64}$"
}
So for example I can decipher:
Last Name: 30 Characters max and accepts A-Z a-z ' ` space -
Is there an easier way to decipher all the rules contained in this file or am I left to comb through the file and look how everything works. I have never worked with regex previously and this is a time sensitive task so I am looking to complete it as soon as I can.
I have used https://regexr.com/ - which gives me some but not all that I am needing and has some issues with the file formatting here and there.
Any suggestions or answers would be greatly appreciated