code: function prepareFlags(pattern, flags) {
      var i;
  
      // Recent browsers throw on duplicate flags, so copy this behavior for nonnative flags
      if (clipDuplicates(flags) !== flags) {
          throw new SyntaxError('Invalid duplicate regex flag ' + flags);
      }
  
      // Strip and apply a leading mode modifier with any combination of flags except g or y
      pattern = nativ.replace.call(pattern, /^\(\?([\w$]+)\)/, function($0, $1) {
          if (nativ.test.call(/[gy]/, $1)) {
              throw new SyntaxError('Cannot use flag g or y in mode modifier ' + $0);
          }
          // Allow duplicate flags within the mode modifier
          flags = clipDuplicates(flags + $1);
          return '';
      });
  
      // Throw on unknown native or nonnative flags
      for (i = 0; i < flags.length; ++i) {
          if (!registeredFlags[flags.charAt(i)]) {
              throw new SyntaxError('Unknown regex flag ' + flags.charAt(i));
          }
      }
  
      return {
          pattern: pattern,
          flags: flags
      };
  }
docs: Checks for flag-related errors, and strips/applies flags in a leading mode modifier. Offloads
  the flag preparation logic from the `XRegExp` constructor.
  
  @private
  @param {String} pattern Regex pattern, possibly with a leading mode modifier.
  @param {String} flags Any combination of flags.
  @returns {Object} Object with properties `pattern` and `flags`.