Regular expression for a language tag (as defined by BCP47)

前端 未结 4 689
情书的邮戳
情书的邮戳 2021-02-05 18:52

I need a regular expression for a language tag as defined by BCP 47.

I know that the full BNF syntax is available at http://www.rfc-editor.org/rfc/bcp/bcp47.txt and th

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 19:10

    An optimized version that works in PHP.

    /^(?(?:en-GB-oed|i-(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|t(?:a[oy]|su))|sgn-(?:BE-(?:FR|NL)|CH-DE))|(?:art-lojban|cel-gaulish|no-(?:bok|nyn)|zh-(?:guoyu|hakka|min(?:-nan)?|xiang)))|(?:(?(?:[A-Za-z]{2,3}(?:-(?[A-Za-z]{3}(?:-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(?:-(?
    
                                     
                  
提交回复
热议问题