void ExpressionRegex::_compile(RegexExecutionState* executionState) const {

    const auto pcreOptions =
        regex_util::flagsToPcreOptions(executionState->options.value_or(""), false, _opName)
            .all_options();

    if (!executionState->pattern) {
        return;
    }

    const char* compile_error;
    int eoffset;

    // The C++ interface pcreccp.h doesn't have a way to capture the matched string (or the index of
    // the match). So we are using the C interface. First we compile all the regex options to
    // generate pcre object, which will later be used to match against the input string.
    executionState->pcrePtr = std::shared_ptr<pcre>(
        pcre_compile(
            executionState->pattern->c_str(), pcreOptions, &compile_error, &eoffset, nullptr),
        pcre_free);
    uassert(51111,
            str::stream() << "Invalid Regex in " << _opName << ": " << compile_error,
            executionState->pcrePtr);

    // Calculate the number of capture groups present in 'pattern' and store in 'numCaptures'.
    const int pcre_retval = pcre_fullinfo(executionState->pcrePtr.get(),
                                          nullptr,
                                          PCRE_INFO_CAPTURECOUNT,
                                          &executionState->numCaptures);
    invariant(pcre_retval == 0);

    // The first two-thirds of the vector is used to pass back captured substrings' start and
    // (end+1) indexes. The remaining third of the vector is used as workspace by pcre_exec() while
    // matching capturing subpatterns, and is not available for passing back information.
    // pcre_compile will error if there are too many capture groups in the pattern. As long as this
    // memory is allocated after compile, the amount of memory allocated will not be too high.
    executionState->capturesBuffer.resize((1 + executionState->numCaptures) * 3);
}
void ExpressionRegex::_compile(RegexExecutionState* executionState) const {

    const auto pcreOptions =
        regex_util::flagsToPcreOptions(executionState->options.value_or(""), false, _opName)
            .all_options();

    if (!executionState->pattern) {
        return;
    }

    const char* compile_error;
    int eoffset;

     
     
     
    executionState->pcrePtr = std::shared_ptr<pcre>(
        pcre_compile(
            executionState->pattern->c_str(), pcreOptions, &compile_error, &eoffset, nullptr),
        pcre_free);
    uassert(51111,
            str::stream() << "Invalid Regex in " << _opName << ": " << compile_error,
            executionState->pcrePtr);

     
    const int pcre_retval = pcre_fullinfo(executionState->pcrePtr.get(),
                                          nullptr,
                                          PCRE_INFO_CAPTURECOUNT,
                                          &executionState->numCaptures);
    invariant(pcre_retval == 0);

     
     
     
     
     
    executionState->capturesBuffer.resize((1 + executionState->numCaptures) * 3);
}