function BuildLanguageTagREs() {
  var alpha = '[a-zA-Z]';
  var digit = '[0-9]';
  var alphanum = '(' + alpha + '|' + digit + ')';
  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 = '(' + irregular + '|' + regular + ')';
  var privateUse = '(x(-' + alphanum + '{1,8})+)';

  var singleton = '(' + digit + '|[A-WY-Za-wy-z])';
  LANGUAGE_SINGLETON_RE = new GlobalRegExp('^' + singleton + '$', 'i');

  var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)';

  var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))';
  LANGUAGE_VARIANT_RE = new GlobalRegExp('^' + variant + '$', 'i');

  var region = '(' + alpha + '{2}|' + digit + '{3})';
  var script = '(' + alpha + '{4})';
  var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})';
  var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' +
                 alpha + '{5,8})';
  var langTag = language + '(-' + script + ')?(-' + region + ')?(-' +
                variant + ')*(-' + extension + ')*(-' + privateUse + ')?';

  var languageTag =
      '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$';
  LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
}
function BuildLanguageTagREs() {
  var alpha = '[a-zA-Z]';
  var digit = '[0-9]';
  var alphanum = '(' + alpha + '|' + digit + ')';
  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 = '(' + irregular + '|' + regular + ')';
  var privateUse = '(x(-' + alphanum + '{1,8})+)';

  var singleton = '(' + digit + '|[A-WY-Za-wy-z])';
  LANGUAGE_SINGLETON_RE = new GlobalRegExp('^' + singleton + '$', 'i');

  var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)';

  var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))';
  LANGUAGE_VARIANT_RE = new GlobalRegExp('^' + variant + '$', 'i');

  var region = '(' + alpha + '{2}|' + digit + '{3})';
  var script = '(' + alpha + '{4})';
  var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})';
  var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' +
                 alpha + '{5,8})';
  var langTag = language + '(-' + script + ')?(-' + region + ')?(-' +
                variant + ')*(-' + extension + ')*(-' + privateUse + ')?';

  var languageTag =
      '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$';
  LANGUAGE_TAG_RE = new GlobalRegExp(languageTag, 'i');
}
function BuildLanguageTagREs ( ) { var alpha = '[a-zA-Z]' ; var digit = '[0-9]' ; var alphanum = '(' + alpha + '|' + digit + ')' ; 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 = '(' + irregular + '|' + regular + ')' ; var privateUse = '(x(-' + alphanum + '{1,8})+)' ; var singleton = '(' + digit + '|[A-WY-Za-wy-z])' ; LANGUAGE_SINGLETON_RE = new GlobalRegExp ( '^' + singleton + '$' , 'i' ) ; var extension = '(' + singleton + '(-' + alphanum + '{2,8})+)' ; var variant = '(' + alphanum + '{5,8}|(' + digit + alphanum + '{3}))' ; LANGUAGE_VARIANT_RE = new GlobalRegExp ( '^' + variant + '$' , 'i' ) ; var region = '(' + alpha + '{2}|' + digit + '{3})' ; var script = '(' + alpha + '{4})' ; var extLang = '(' + alpha + '{3}(-' + alpha + '{3}){0,2})' ; var language = '(' + alpha + '{2,3}(-' + extLang + ')?|' + alpha + '{4}|' + alpha + '{5,8})' ; var langTag = language + '(-' + script + ')?(-' + region + ')?(-' + variant + ')*(-' + extension + ')*(-' + privateUse + ')?' ; var languageTag = '^(' + langTag + '|' + privateUse + '|' + grandfathered + ')$' ; LANGUAGE_TAG_RE = new GlobalRegExp ( languageTag , 'i' ) ; }
Builds a regular expresion that validates the language tag
against bcp47 spec.
Uses http://tools.ietf.org/html/bcp47, section 2.1, ABNF.
Runs on load and initializes the global REs.
Builds a regular expresion that validates the language tag against bcp47 spec . Uses http : // tools . ietf . org / html / bcp47 section 2 . 1 ABNF . Runs on load and initializes the global REs .