code: function (pattern) {
        var match;
  
        if (pattern.test) {
          return pattern;
        } else {
          match = pattern.match(REGEXP_PATTERN);
          if (match) {
            return new RegExp(match[1], match[2]);
          } else {
            throw ('Expected ' + pattern + ' to be a RegExp');
          }
        }
      }
docs: Converts the given pattern to a RegExp.
  The pattern can either be a RegExp object or a string containing a regular expression (`/regexp/`).
  This implementation is based on the AngularJS ngPattern validator.
  @param pattern the pattern
  @returns {RegExp} the RegExp