0

I am trying to match symbols with following regex: ((?<!-)[<>])

C++ Function:

vector<string> regexSearch(string str, string regEx) {
    vector <string> result;
    smatch matches;
    regex reg(regEx);

    // Search string
    while (regex_search(str, matches, reg)) {
        result.push_back(matches.str(1));
        str = matches.suffix().str();
    }

    return result;
}

Function call:

symbols = regexSearch(input, "((?<!-)[<>])");

Input is a string read from .txt file and looks like this:

4 5
1 > 2
3 > 2
3 < 4
1 < 3
4 > 2

When I run the program it crashes and I get the Invalid special open parenthesis error.

fingust
  • 60
  • 1
  • 6
  • 1
    [This](https://stackoverflow.com/questions/43503110/what-is-an-alternative-for-lookbehind-with-c-regex) and [this](https://stackoverflow.com/questions/43503110/what-is-an-alternative-for-lookbehind-with-c-regex) might help you - C++ doesn't support lookbehinds; it's ECMAScript regex – ctwheels Oct 10 '19 at 15:36
  • For regex, it's better to send raw strings instead. https://en.cppreference.com/w/cpp/language/string_literal – sweenish Oct 10 '19 at 17:46

0 Answers0