|
export var match1 = /\d/; |
|
export var match2 = /\d\d/; |
|
export var match3 = /\d{3}/; |
|
export var match4 = /\d{4}/; |
|
export var match6 = /[+-]?\d{6}/; |
|
export var match1to2 = /\d\d?/; |
|
export var match3to4 = /\d\d\d\d?/; |
|
export var match5to6 = /\d\d\d\d\d\d?/; |
|
export var match1to3 = /\d{1,3}/; |
|
export var match1to4 = /\d{1,4}/; |
|
export var match1to6 = /[+-]?\d{1,6}/; |
|
|
|
export var matchUnsigned = /\d+/; |
|
export var matchSigned = /[+-]?\d+/; |
|
|
|
export var matchOffset = /Z|[+-]\d\d:?\d\d/gi; |
|
export var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; |
|
|
|
export var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; |
|
|
|
|
|
|
|
export var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; |
|
|
|
|
|
import hasOwnProp from '../utils/has-own-prop'; |
|
import isFunction from '../utils/is-function'; |
|
|
|
var regexes = {}; |
|
|
|
export function addRegexToken (token, regex, strictRegex) { |
|
regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) { |
|
return (isStrict && strictRegex) ? strictRegex : regex; |
|
}; |
|
} |
|
|
|
export function getParseRegexForToken (token, config) { |
|
if (!hasOwnProp(regexes, token)) { |
|
return new RegExp(unescapeFormat(token)); |
|
} |
|
|
|
return regexes[token](config._strict, config._locale); |
|
} |
|
|
|
|
|
function unescapeFormat(s) { |
|
return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { |
|
return p1 || p2 || p3 || p4; |
|
})); |
|
} |
|
|
|
export function regexEscape(s) { |
|
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); |
|
} |
|
|