e120f86fa13fac66b02e94765b317f6a77cfd4a1c36fbbfb5beb44de3a43dfbda2de54beb3c4a260aff632246f3cfbde2b6a50e810083bdbaef1234f70761e 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export var match1 = /\d/; // 0 - 9
  2. export var match2 = /\d\d/; // 00 - 99
  3. export var match3 = /\d{3}/; // 000 - 999
  4. export var match4 = /\d{4}/; // 0000 - 9999
  5. export var match6 = /[+-]?\d{6}/; // -999999 - 999999
  6. export var match1to2 = /\d\d?/; // 0 - 99
  7. export var match3to4 = /\d\d\d\d?/; // 999 - 9999
  8. export var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  9. export var match1to3 = /\d{1,3}/; // 0 - 999
  10. export var match1to4 = /\d{1,4}/; // 0 - 9999
  11. export var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  12. export var matchUnsigned = /\d+/; // 0 - inf
  13. export var matchSigned = /[+-]?\d+/; // -inf - inf
  14. export var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  15. export var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  16. export var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  17. // any word (or two) characters or numbers including two/three word month in arabic.
  18. // includes scottish gaelic two word and hyphenated months
  19. export var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  20. import hasOwnProp from '../utils/has-own-prop';
  21. import isFunction from '../utils/is-function';
  22. var regexes = {};
  23. export function addRegexToken (token, regex, strictRegex) {
  24. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  25. return (isStrict && strictRegex) ? strictRegex : regex;
  26. };
  27. }
  28. export function getParseRegexForToken (token, config) {
  29. if (!hasOwnProp(regexes, token)) {
  30. return new RegExp(unescapeFormat(token));
  31. }
  32. return regexes[token](config._strict, config._locale);
  33. }
  34. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  35. function unescapeFormat(s) {
  36. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  37. return p1 || p2 || p3 || p4;
  38. }));
  39. }
  40. export function regexEscape(s) {
  41. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  42. }