I’m trying to take a string and then retrieve the required elements from it. At the moment, I can’t seem to find a way of doing it because the input string that will change from time to time, although the elements won’t.
My code so far is below. What I want to do is extract the '.V/' from the string when parsed.
My code so far below will work, but I need it to be more generic as there are many elements within the inputted string
-
i.e
.V/ER/12/FRG/45S/16JAN .E/45/SHAM/CAMP/2and I would need to retrieve
.V/and.E/
std::vector<std::string>elements;
std::string input = ".V/ER/12/FRG/45S/16JAN ";
bool result = qi::parse(input.begin(),input.end(),
*(*(qi::char_ - " /ER/12/FRG/45S/16JAN\n") >> " /ER/12/FRG/45S/16JAN\n"),
elements
);
I’d really suggest using a regular expression (boost regex or std::regex) for this job.
The regular expression would probably look like
Here is a bit of spirit in case you really need it:
This will output
If you want to show ‘.E/’ there, there are many ways about it, e.g.
output:
Bonus
To show how to include the ‘tail’ of the line, possibly storing into map:
would output