Assign RegEx submatches to variables or map (C++/C)
- by Michael
I need to extract the SAME type of information (e.g. First name, Last Name, Telephone, ...), from numerous different text sources (each with a different format & different order of the variables of interest).
I want a function that does the extraction based on a regular expression and returns the result as DESCRIPTIVE variables. In other words, instead of returning each match result as submatch[0], submatch[1], submatch[2], ..., have it do EITHER of the following:
1.)
return std::map so that the submatches can be accessed via:
submatch["first_name"], submatch["last_name"], submatch["telephone"]
2.)
return a variables with the submatches so that the submatches can be accessed via:
submatch_first_name, submatch_last_name, submatch_telephone
I can write a wrapper class around boost::regex to do #1, but I was hoping there would be a built-in or a more elegant way to do this in C++/Boost/STL/C.