I need to get some strings from a given line as below:
{"username":"wrongpass", "password":"abc", "email":"example@gmail.com"}
To be more specific, those in ""
are needed. Here is my code:
#include <regex>using namespace std;int main(){ regex re(R"&(^{("(username|password|email)")\s*:\s*"(.*)"\s*,\s*("(username|password|email)")\s*:\s*"(.*)"\s*,\s*("(username|password|email)")\s*:\s*"(.*)"}$)&"); return 0;}
It is successfully compiled with -std=c++11
using gcc version 8.1.0. But it throws an exception when running:
terminate called after throwing an instance of 'std::regex_error' what(): regex_error
I have no idea why it gives such an exception. I've searched online and found some similar problems, but they were mainly due to using a compiler(gcc) that was too old to support regex.
Thanks for your help.