Boost logo

Boost Users :

Subject: [Boost-users] regular expression to extract numbers
From: Neil Sutton (neilmsutton_at_[hidden])
Date: 2012-12-02 19:10:11


Hi,
I am new to using boost and am trying to learn basics so I can use regex
features in my code.
In my test program, I want a function to simply extract some numbers that
follow after a certain string pattern and then to read those numbers into a
vector.

This is an outline of what i would like to do:

// function definition
#ifndef findnumbers.h
#define findnumbers.h

#include <string>
#include <fstream>
#include <vector>
#include <boost/regex.hpp>
#endif

void findnumbers (ifstream& afile)
{
// assume file is opened in main - i have passed a reference
boost::regex expression ( ....having trouble with this);
// search for matches - there will be a fixed number of numbers e.g 10
std::string const_iterator start, end;
start = afile.begin( );
end = afile.end( );
std::vector<int> results;
boost::match_results<std::vector<int>::const_iterator> what;
for(int count = 0; count !=10; count++)
{
boost::regex_search(start,end,what,expression)
{
//if a number is found place in the vector
results.push_back(count);
}

So the first problem I have is defining a correct expression. The pattern
has the format "sometext>NUMBERS<sometext" newline. The NUMBERS may be one
or two digits combined and the pattern is repeated 10 times. I have
searched the archives and tried to build something based on the examples I
have read, but cannot seem to find a working solution. Can anyone help
please in defining an expression?

I do not need a solution to my function overall as I should be able to
write it correctly once I know how to define the pattern.

Kind regards



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net