I dont understand exactly how the escaping with regex word. I try to detect a "+". I know it is also a special sign of regex to indicate that there follows one ore more signs.
From my understanding these special signs need to be escaped with "\". For + this seems to work with "." If i however escape a plus with "+ i get a runtime exception.
"matched. regex_error(error_badrepeat): One of *?+{ was not preceded by a valid reguar expression."
So I assume it is not correctly escaped.
Example:
#include <iostream>
#include <string>
#include <regex>
#include <exception>
int main()
try {
std::regex point("\.");
std::string s1 = ".";
if (std::regex_match(s1, point))
std::cout << "matched" << s1;
std::regex plus("\+");
std::string s2 = "+";
if (std::regex_match(s2, plus))
std::cout << "matched" << s2;
char c;
std::cin >> c;
}
catch (std::runtime_error& e) {
std::cerr << e.what()<<'\n';
char c;
std::cin >> c;
}
catch (...) {
std::cerr << "unknown error\n";
char c;
std::cin >> c;
}