lundi 28 novembre 2016

C++11 regular expression to match a string exaclty - regex_match

I am trying to read a file and get data to implement an employee management system. I tried to validate the readings from the file using c++11's regex library. I want to match id's that looks like EM32 or EM231

This is my regex:

regex emp_regex("EM[[:digit:]]+", regex_constants::extended);
smatch matcher;

I 've splitted the line to get the first entry, which is the ID I need to validate.

vector<string> tokens;
split(tokens, line, is_any_of(","));

Here is my if condition:

if(regex_match(tokens[0], matcher, emp_regex))
{
  ...
}

Aucun commentaire:

Enregistrer un commentaire