I need to validate whether a given string is a valid mDNS address. Examples of these are listed here:
a2aadd61-85d9-4be6-a36c-267ad65917d3.local
ccd58700-cdd5-4c1f-8098-5bc306f1ce77.local
bb4115cd-1f39-42b0-9433-e59533c9c771.local
3b382824-24bf-457a-a7d6-b6e25e4d79bf.local
9284cbaa-2933-45e3-9ae2-c0cccae54b68.local
619281fb-6426-44fa-8d0f-9e58ce415e3e.local
541d8a99-b1a5-46f4-96f1-e31f30b3cb99.local
2feb782f-ea40-4a37-b843-5b5b4fe1860e.local
Is this possible? I am new to regex and can't seem to find any regex examples for this particular string. This was my attempt at making a regex test:
let valid = 'a2aadd61-85d9-4be6-a36c-267ad65917d3.local';
let invalid = 'not-valid-233q4q22eqwr-q3rhHE02n333r4tsefs.local';
let regex = \([a-zA-Z1-9]+){8}-([a-zA-Z1-9]){4}-([a-zA-Z1-9]){4}-([a-zA-Z1-9]){12}\.local\;
regex.test(valid)
Edit: I tried this on regex101.com and it didn't work. Any help? THanks!
SOLUTIONS:
I got it to work using this:
let valid = 'a2aadd61-85d9-4be6-a36c-267ad65917d3.local';
let invalid = 'not-valid-233q4q22eqwr-q3rhHE02n333r4tsefs.local';
let regex = /(^[a-zA-Z1-90]{8})-([a-zA-Z1-90]{4})-([a-zA-Z1-90]{4})-([a-zA-Z1-90]{4})-([a-zA-Z1-90]{12})\.local/;
console.log(regex.test(valid)) //=> true
console.log(regex.test(invalid)) //=> false
Thanks!