|
Boost Users : |
From: Jeff (jeff_j_dunlap_at_[hidden])
Date: 2007-04-10 15:51:30
Dear forum members:
Iâm hoping that someone can copy and compile the code below and tell me what is
wrong with my expression. I am trying to write a pattern that produces the
following match and submatch:
MATCH:
<a href="http://test1.com">TEST #1</a>
SUBMATCH:
http://test1.com
// main.cpp
#include <boost/regex.hpp>
#include <iostream>
using namespace std;
using namespace boost;
int main() {
// here is the data, please note the minor âhref=â differences.
string sText =
"<a href=\"http://test1.com\">TEST #1</a>"
"<a href =\"http://test2.com\">TEST #2</a>"
"<a href= \"http://test3.com\">TEST #3</a>"
"<a href = \"http://test4.com\">TEST #4</a>"
"<a href=\"http://test5.com\">TEST #5</a>";
// the following 4 patterns were my bet attempts
char exp[] =
"<a href(.*?)</a>";
"<a href\s*=\s*\"(.*?)\"";
"<a href=(.*?)</a>";
"<a href\s*=\s*\"(.*?)</a>"
int subs[] = {0,1};
regex e(exp, regex::normal | regbase::icase);
sregex_token_iterator i(sText.begin(), sText.end(), e, subs);
sregex_token_iterator j;
while(i != j) {
cout << "*******************************" << endl;
cout << *i++ << endl;
cout << *i++ << endl;
}
return 0;
}
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