vendredi 10 mars 2017

C++ regex to extract variables from a scripting file

So I have a scripted file in which some variables are assigned using the # sign, followed by the assignment operator (=), and then a string. All of this is without spaces. Sometimes, there will be a comment (starting with the ! symbol) or some extra whitespace. For example:

#mat=3     !mat denotes a material number

I want to use C++'s regex utility to extract '#mat' and '3'. I couldn't figure out the regex pattern. Even if I had a pattern, I didn't know how to extract '#mat' and '3' specifically from that line. When I would use cout for the smatch array of regex_search, I would get the entire line.

Any suggestions? I would greatly appreciate your help/advice.

Aucun commentaire:

Enregistrer un commentaire