Boost::regex

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.