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

前端 未结 4 693
情书的邮戳
情书的邮戳 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:15

    Javascript polices duplicate named capture groups so you have to change the 2nd use of ? to e.g. ?. Compiles to:

    /^((?(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))|((?([A-Za-z]{2,3}(-(?[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?
    
                                     
                  
提交回复
热议问题