sub_match Class

Describes a submatch.

template<class BidIt>
    class sub_match
        : public std::pair<BidIt, BidIt> {
public:
    bool matched;
    int compare(const sub_match& right) const;
    int compare(const basic_string<value_type>& right) const;
    int compare(const value_type *right) const;
    difference_type length() const;
    operator basic_string<value_type>() const;
    basic_string<value_type> str() const;
    typedef typename iterator_traits<BidIt>::value_type value_type;
    typedef typename iterator_traits<BidIt>::difference_type difference_type;
    typedef BidIt iterator;
    };

Parameters

  • BidIt
    The iterator type for submatches.

Remarks

The template class describes an object that designates a sequence of characters that matched a capture group in a call to regex_match Function or to regex_search Function. Objects of type match_results Class hold an array of these objects, one for each capture group in the regular expression that was used in the search.

If the capture group was not matched the object's data member matched holds false, and the two iterators first and second (inherited from the base std::pair) are equal. If the capture group was matched, matched holds true, the iterator first points to the first character in the target sequence that matched the capture group, and the iterator second points one position past the last character in the target sequence that matched the capture group. Note that for a zero-length match the member matched holds true, the two iterators will be equal, and both will point to the position of the match.

A zero-length match can occur when a capture group consists solely of an assertion, or of a repetition that allows zero repeats. For example:

"^" matches the target sequence "a"; the sub_match object corresponding to capture group 0 holds iterators that both point to the first character in the sequence.

"b(a*)b" matches the target sequence "bb"; the sub_match object corresponding to capture group 1 holds iterators that both point to the second character in the sequence.

Requirements

Header: <regex>

Namespace: std

See Also

Reference

<regex>

sub_match Class

regex_match Function

regex_search Function

Other Resources

<regex> Members