我需要
BCP 47定义的
language tag的正则表达式.
我知道在http://www.rfc-editor.org/rfc/bcp/bcp47.txt可以使用完整的BNF语法,我可以使用它来编写自己的,但希望有一个已经在那里.
看起来像这样:
原文链接:https://www.f2er.com/regex/356632.html^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux| i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban| cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language> ([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8}) (-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8} |[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))* (-(?<privateUse>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUse>x(-[A-Za-z0-9]{1,8})+))$
var regular = "(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)"; var irregular = "(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)"; var grandfathered = "(?<grandfathered>" + irregular + "|" + regular + ")"; var privateUse = "(?<privateUse>x(-[A-Za-z0-9]{1,8})+)"; var singleton = "[0-9A-WY-Za-wy-z]"; var extension = "(?<extension>" + singleton + "(-[A-Za-z0-9]{2,8})+)"; var variant = "(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3})"; var region = "(?<region>[A-Za-z]{2}|[0-9]{3})"; var script = "(?<script>[A-Za-z]{4})"; var extlang = "(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2})"; var language = "(?<language>([A-Za-z]{2,3}(-" + extlang + ")?)|[A-Za-z]{4}|[A-Za-z]{5,8})"; var langtag = "(" + language + "(-" + script + ")?" + "(-" + region + ")?" + "(-" + variant + ")*" + "(-" + extension + ")*" + "(-" + privateUse + ")?" + ")"; var languageTag = @"^(" + grandfathered + "|" + langtag + "|" + privateUse + ")$"; Console.WriteLine(languageTag);
我不能保证其正确性(我可能会打字错误),但附录A中的示例可以正常工作.
根据您的环境,您可能需要删除命名的捕获组“?&…”.