0

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.

sandun dhammika
  • 881
  • 3
  • 12
  • 31
  • What version of what compiler? – ildjarn May 30 '14 at 04:48
  • I am getting the same error with g++ 4.7.3 when the `regex` contains just `[@]`, and just `[g]`, and just `[m]`. I suspect there is a compiler bug dealing with `[ ]`. – R Sahu May 30 '14 at 05:01
  • GCC prior to 4.9 did not implement `std::regex`, so it's a libstdc++ bug, not a compiler bug. – ildjarn May 30 '14 at 05:03

0 Answers0