match_results::suffix
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

match_results::suffix

Gets sequence after last submatch.

const_reference suffix() const;

The member function returns a reference to an object of type sub_match<BidIt> that points to the character sequence that begins at (*this)[size() - 1].second and ends at the end of the target sequence, that is, it points to the text that follows the matched subsequence.

 

// std_tr1__regex__match_results_suffix.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    std::tr1::regex rx("c(a*)|(b)"); 
    std::tr1::cmatch mr; 
 
    std::tr1::regex_search("xcaaay", mr, rx); 
 
    std::cout << "prefix: matched == " << std::boolalpha 
        << mr.prefix().matched 
        << ", value == " << mr.prefix() << std::endl; 
    std::cout << "whole match: " << mr.length() << " chars, value == " 
        << mr.str() << std::endl; 
    std::cout << "suffix: matched == " << std::boolalpha 
        << mr.suffix().matched 
        << ", value == " << mr.suffix() << std::endl; 
    std::cout << std::endl; 
 
    std::string fmt("\"c(a*)|(b)\" matched \"$0\"\n" 
        "\"(a*)\" matched \"$1\"\n" 
        "\"(b)\" matched \"$2\"\n"); 
    std::cout << mr.format(fmt) << std::endl; 
    std::cout << std::endl; 
 
// index through submatches 
    for (size_t n = 0; n < mr.size(); ++n) 
        { 
        std::cout << "submatch[" << n << "]: matched == " << std::boolalpha 
            << mr[n].matched << 
            " at position " << mr.position(n) << std::endl; 
        std::cout << "  " << mr.length(n) 
            << " chars, value == " << mr[n] << std::endl; 
        } 
    std::cout << std::endl; 
 
// iterate through submatches 
    for (std::tr1::cmatch::iterator it = mr.begin(); it != mr.end(); ++it) 
        { 
        std::cout << "next submatch: matched == " << std::boolalpha 
            << it->matched << std::endl; 
        std::cout << "  " << it->length() 
            << " chars, value == " << *it << std::endl; 
        } 
    std::cout << std::endl; 
 
// other members 
    std::tr1::cmatch mr1(mr); 
    mr = mr1; 
    mr.swap(mr1); 
 
    char buf[10]; 
    *mr.format(&buf[0], "<$0>") = '\0'; 
    std::cout << &buf[0] << std::endl; 
    std::cout << "empty == " << std::boolalpha << mr.empty() << std::endl; 
 
    std::tr1::cmatch::allocator_type al = mr.get_allocator(); 
    std::tr1::cmatch::string_type str = std::string("x"); 
    std::tr1::cmatch::size_type maxsiz = mr.max_size(); 
    std::tr1::cmatch::char_type ch = 'x'; 
    std::tr1::cmatch::difference_type dif = mr.begin() - mr.end(); 
    std::tr1::cmatch::const_iterator cit = mr.begin(); 
    std::tr1::cmatch::value_type val = *cit; 
    std::tr1::cmatch::const_reference cref = val; 
    std::tr1::cmatch::reference ref = val; 
 
    maxsiz = maxsiz;  // to quiet "unused" warnings 
    if (ref == cref) 
        ch = ch; 
    dif = dif; 
 
    return (0); 
    } 
 
prefix: matched == true, value == x whole match: 4 chars, value == caaa suffix: matched == true, value == y "c(a*)|(b)" matched "caaa" "(a*)" matched "aaa" "(b)" matched "" submatch[0]: matched == true at position 1 4 chars, value == caaa submatch[1]: matched == true at position 2 3 chars, value == aaa submatch[2]: matched == false at position 6 0 chars, value == next submatch: matched == true 4 chars, value == caaa next submatch: matched == true 3 chars, value == aaa next submatch: matched == false 0 chars, value == <caaa> empty == false

Header: <regex>

Namespace: std::tr1

Show:
© 2016 Microsoft