Common usage:
Boost::regex Express;
Regex_match (str,express); bool
Smatch what;
Cmatch what;
typedef match_results<const Char*> Cmatch;
typedef match_results<std::string::const_iterator> Smatch;
Regex_search (str,what,express); bool
WHAT[0];
WHAT[1];
Regex_replace (Str,express,kongge);
① matches a full string with multiple results
Primarily for string
Boost::sregex_iterator ite (Str.begin (), Str.end (), express);
Boost::sregex_iterator Endite;
while (ite! = endite)
{
cout<<*ite<<endl;
ite++;
}
Ii
Char *p = "www.baidu.com---dffsfdsf--f-ff www.google.comddfdsffd";
Boost::regex exp ("\\w{3}\\" ( \\w+\\.) + (NET|COM|CN) ");
char *tmp = p;
Cmath what;
while (Boost::regex_search (TMP, what, exp))
{
cout<<what[0]<<endl;
TMP = What[0].second;
}
③ can be obtained by const *P = S.c_str ();
Const_reference operator[] (int n) const: Returns a sub_match reference, when N=0 returns a matching result of [First,last], when 0<n<=size, returns the matching result of the corresponding tuple,
When N>size returns a matched value as a false sub_match structure, tuples correspond to the order of the left brackets and sub_match, starting with 1
A well-written post
Http://www.cnblogs.com/hucn/archive/2011/05/09/2041490.html
Boost::regex iterator
Http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/ref/regex_iterator.html
Boost::regex