I'm trying to parse my email using std::regex.
This is my code bellow.
#include <iostream>
#include <stdio.h>
#include <regex>
/* the main method */
int main( int argc,char** argv)
{
std::string input_string = "sandundhammikaperera@gmail.com";
// create a new regex object //
//std::regex new_regex_object("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
std::regex new_regex_object("(.*)[@] (.*)(.*)");
int result = std::regex_match ( input_string,new_regex_object);
if(result){
printf("regex have been matched.\n");
}
else{
printf("regex didn't match.\n");
}
// then parse it for the parttern //
return 0;
}
But it throws an exception and I could not figure out why on any of the syntax described in here. Is that mean character class wasn't supported in my version of library ? I've included -std=c++11 flag to CFLAGS and LDFLAGS too , but still gives this exception.
root@kali:/src/exercises/regex# ./regex_test
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Aborted
Any idea why this is happening. It seems like that my version of std::regex does not support for character class yet.