można potwierdzić z tym:
/^[a-z]{2,3}(?:-[A-Z]{2,3}(?:-[a-zA-Z]{4})?)?$/
Oto jak to działa
^ <- Starts with
[a-z] <- From a to z (lower-case)
{2,3} <- Repeated at least 2 times, at most 3
(?: <- Non capturing group
- <- The "-" character
[A-Z] <- From a to z (upper-case)
{2,3} <- Repeated at least 2 times, at most 3
(?: <- Non capturing group
- <- The "-" character
[a-zA-Z] <- from a to Z (case insensitive)
{4} <- Repeated 4 times
) <- End of the group
? <- Facultative
) <- End of the group
? <- Facultative
$ <- Ends here
Można również zastąpić ostatni non grupę przechwytywania przez (?:-(?:Cyrl|Latn))?
jeśli tylko opcje są Cyrl i Latn
To łącze powinno zostać usunięte, ponieważ prowadzi do przejęcia strony. –