docs: function XRegExp(pattern, flags) {
          var context = {
                  hasNamedCapture: false,
                  captureNames: []
              },
              scope = defaultScope,
              output = '',
              pos = 0,
              result,
              token,
              generated,
              appliedPattern,
              appliedFlags;
  
          if (XRegExp.isRegExp(pattern)) {
              if (flags !== undefined) {
                  throw new TypeError('Cannot supply flags when copying a RegExp');
              }
              return copyRegex(pattern);
          }
  
          // Copy the argument behavior of `RegExp`
          pattern = pattern === undefined ? '' : String(pattern);
          flags = flags === undefined ? '' : String(flags);
  
          if (XRegExp.isInstalled('astral') && flags.indexOf('A') === -1) {
              // This causes an error to be thrown if the Unicode Base addon is not available
              flags += 'A';
          }
  
          if (!patternCache[pattern]) {
              patternCache[pattern] = {};
          }
  
          if (!patternCache[pattern][flags]) {
              // Check for flag-related errors, and strip/apply flags in a leading mode modifier
              result = prepareFlags(pattern, flags);
              appliedPattern = result.pattern;
              appliedFlags = result.flags;
  
              // Use XRegExp's tokens to translate the pattern to a native regex pattern.
              // `appliedPattern.length` may change on each iteration if tokens use `reparse`
              while (pos < appliedPattern.length) {
                  do {
                      // Check for custom tokens at the current position
                      result = runTokens(appliedPattern, appliedFlags, pos, scope, context);
                      // If the matched token used the `reparse` option, splice its output into the
                      // pattern before running tokens again at the same position
                      if (result && result.reparse) {
                          appliedPattern = appliedPattern.slice(0, pos) +
                              result.output +
                              appliedPattern.slice(pos + result.matchLength);
                      }
                  } while (result && result.reparse);
  
                  if (result) {
                      output += result.output;
                      pos += (result.matchLength || 1);
                  } else {
                      // Get the native token at the current position
                      token = XRegExp.exec(appliedPattern, nativeTokens[scope], pos, 'sticky')[0];
                      output += token;
                      pos += token.length;
                      if (token === '[' && scope === defaultScope) {
                          scope = classScope;
                      } else if (token === ']' && scope === classScope) {
                          scope = defaultScope;
                      }
                  }
              }
  
              patternCache[pattern][flags] = {
                  // Cleanup token cruft: repeated `(?:)(?:)` and leading/trailing `(?:)`
                  pattern: nativ.replace.call(output, /\(\?:\)(?:[*+?]|\{\d+(?:,\d*)?})?\??(?=\(\?:\))|^\(\?:\)(?:[*+?]|\{\d+(?:,\d*)?})?\??|\(\?:\)(?:[*+?]|\{\d+(?:,\d*)?})?\??$/g, ''),
                  // Strip all but native flags
                  flags: nativ.replace.call(appliedFlags, /[^gimuy]+/g, ''),
                  // `context.captureNames` has an item for each capturing group, even if unnamed
                  captures: context.hasNamedCapture ? context.captureNames : null
              };
          }
  
          generated = patternCache[pattern][flags];
          return augment(
              new RegExp(generated.pattern, generated.flags),
              generated.captures,
              pattern,
              flags
          );
      }