I'd like to use a regular expression to filter culture names (like en-US or pt-BR). Anyone has any idea?
Try this:
^[a-z]{2}-[A-Z]{2}$
Or more general (see RFC 4647):
^[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8})*$
If you want follow the RFC 4646 format for the culture name (who is <languagecode2>-<country/regioncode2>
, where <languagecode2>
is the language code and <country/regioncode2>
is the subculture code)
Example: "en", "en-UK", "fr", "fr-FR", ...
Use this Regex:
^[a-z]{2}(-[A-Z]{2})*
C# code sample
Regex.IsMatch(culture, @"^[a-z]{2}(-[A-Z]{2})*$")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With