C++ Regular Expressions

From Schmid.wiki
Jump to: navigation, search

Example

This example requires Boost.

// link with -lboost_regex
#include <boost/regex.hpp>
#include <iostream>

void check(const char *s) {

    static const boost::regex re("h(i|ello)", boost::regex::icase);
    if(regex_match(s, re))
         std::cout << s << " matches.\n";
    else std::cout << s << " doesn't match.\n";
}

main() {
    check("HELLO");
    check("hi there");
}

// output:
// HELLO matches.
// hi there doesn't match.
Personal tools