OJ C++ Compiler does NOT support regex or it is disabled for some reason (security)?

  • 1

    I submitted the code below to OJ and get all kinds of errors.

    1. ‘regex’ was not declared in this scope
    2. ‘regex’ is not a member of ‘std’, when I put std::regex

    I also tried #include <regex> and using namespace std; but nothing can resolve the error.

    It appears to me the C++ compiler of OJ does not implement regex at all?

        class Solution {
                bool isNumber(const char *s) {
                    string test(s);
                    regex e("your expression");
                    return regex_match(test,e);

  • 1

    std::regex is part of the C++11 STL, and it's not clear which compiler directives are used by this OJ, it could be they just didn't put the -std=c++11 part.

  • 0

    Thank you for your answer!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.