I’m pretty new with regexp and I can’t get my function doing what I would like.
I have a long string, and I want to extract from it, 3 variables.
My string looks :
Infoname/info :
Input_Device_Name GTape Buffer_Size 16384 Acquisition_Event_Rate 163691.000000
Acquisition_Buffer_Rate 14873.333008 Acquisition_Succes_Rate 100.000000
And my goal is to store 163691.000000, 14873.333008 and 100.000000 in three differents variables.
What is the fastest and nicest way to do it please ?
Thank you,
eo
You could use the following regex to look for it:
This should catch the three values assuming that your text stays the same and that your numbers always take this form (i.e. are positive and not in exponential form.) Note that only the last three numbers are captured by putting brackets round them.
If you use boost regex, you could do something like this:
…
Where
inputTextStringcontains the line of text you want to parse, so if this is coming from a file say, you would want to place this code in a loop. Thewhatvariable is a vector of all the matching text thoughwhat[0]contains the whole line and so can be ignored unless you need it. Last but not least, remember to double escape the ‘space’ character class otherwise it will already be processed (or generate an error or warning) by the compiler prior to being presented to the regex processor. Also, please note that I’ve not had time to compile this, though it is based on working codeWatch out for trailing, leading space on your input file and use
^and$to mark the beginning or end of the line respectively if it helps.