I am looking for an regex to control language code for my localization service.
which need to control the format
en en-US
String regex1 = "^[a-z]{2}";
String regex2 = "^[a-z]{2}-[A-Z]{2}$";
I came up with these two, but I want to combine them .
How could I combine them?
Thanks.
CodePudding user response:
This is the regular expression that combines those 2. Making the first part mandatory, and the second part optional:
[a-z]{2}(-[A-Z]{2})?