Hello, I am learning the basics of regular expression syntax and have been looking at the following example:
#include <iostream>
#include <fstream>
#include <string>
#include <boost/regex.hpp>
#include <boost/xpressive/xpressive.hpp>
using namespace boost::xpressive;
int main()
{
std::ifstream input("myfile");
if(input)
std::cout << "Success\n";
else
std::cout << "fail\n";
std::string line;
std::string data;
while (getline(input, line))
{
data += line;
}
std::string const &ref = data;
mark_tag day(1), month(2), year(3), delim(4);
sregex date = (month= repeat<1,2>(_d)) // find the month ...
>> (delim= (set= '/','-')) // followed by a delimiter ...
>> (day= repeat<1,2>(_d)) >> delim // and a day followed by the same
>> (year= repeat<1,2>(_d >> _d)); // and the year.
smatch what;
if( regex_search(ref, what, date ) )
{
std::cout << what[0] << '\n'; // whole match
std::cout << what[day] << '\n'; // the day
std::cout << what[month] << '\n'; // the month
std::cout << what[year] << '\n'; // the year
std::cout << what[delim] << '\n'; // the delimiter
}
return 0;
}
My problem is very simple and I am sorry to be asking about it. I want to include some literal wording in my regular expression. For example, before the program outputs the date it also searches for the words "Football results for" - (then date is output). Please can you show me how to prefix this regular expression with the literal words? My compiler see the 'for' as a c++ keyword, without more.