Matching Exactly






Matching Exactly

template<class Elem, class RXtraits>
  bool regex_match (
    const Elem *ptr,
    const basic_regex <Elem, RXtraits>& rgx,
    match_flag_types flags = match_default);
template<class IOtraits, class IOalloc,
    class Elem, class RXtraits>
  bool regex_match (
    const basic_string <Elem, IOtraits, IOalloc>& str,
    const basic_regex <Elem, RXtraits>& rgx,
    match_flag_types flags = match_default);
template<class BidIt, class Elem, class RXtraits>
  bool regex_match (
    BidIt first, Bidit last,
    const basic_regex <Elem, RXtraits>& rgx,
    match_flag_types flags = match_default);

The function templates return true only if the regular expression argument rgx matches the entire target sequence.

Figure. Using regex_match (regexsrch/match.cpp)

#include <regex>
#include <iomanip>
#include <iostream>
using std::tr1::regex; using std::tr1::regex_match;
using std::cout; using std::setw;

void show_match (const regex & rgx, const char *str)
  { // check for match
  cout << setw (10) << str <<": ";
  if (regex_match (str, rgx))
    cout << "matches\n";
  else
    cout << "doesn' t match\n";
  }

int main()
  { // demonstrate exact match
  regex rgx("b(c*) d");
  show_match(rgx, "bd");                        // matches
  show_match(rgx, "d");                         // doesn't match
  show_match(rgx, "bcd");                     // matches
  show_match(rgx, "bc");                      // doesn't match
  show_match(rgx, "abd");                     // doesn't match
  show_match(rgx, "bde");                     // doesn't match
  return 0;
  }



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows