I need a regex with max 222 chars
Examples:
GOOD:
asd.asd.asd.asd.asd.aadas.asdasdasd
as-d.asd.a-sd
BAD:
.asd.asd
-asd.-asd
.-asd.asd
asd.asd.
asd.asd-
asd.asd.-
asd.asd-.
asd.asd--
asd..
asd.asd-.asd
.-
asd--asd..asd
I ended up with something like this
^[^-.]((?!--)[a-zA-Z0-9\-]\.?[^-]){1,100}[^-.]$
but it does not cover this case like asd.asd-.asd
this is regex for platform iOS Bundle ID in app registration.
You might write it without the hyphen in the character class [a-zA-Z0-9\-]
(Note that if the -
is at the start or end, you don't have to escape it)
^(?=.{1,100}$)[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*$
^
Start of string(?=.{1,100}$)
Assert 1-100 chars[a-zA-Z0-9]+
Repeat 1+ times matching any of the listed(?:[-.][a-zA-Z0-9]+)*
Optionally repeat either -
or .
and repeat 1+ times any of the listed$
End of string