Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22298

std::regex constructor throwing std::regex_error with what(): regex_error

$
0
0

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.


Viewing all articles
Browse latest Browse all 22298

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>