Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.

basic_regex::assign

Assigns a value to the regular expressoin object.

basic_regex& assign(const basic_regex& right);
basic_regex& assign(const Elem *ptr,
    flag_type flags = ECMAScript);
basic_regex& assign(const Elem *ptr, size_type len,
    flag_type flags = ECMAScript);
template<class STtraits, class STalloc>
    basic_regex& assign(const basic_string<Elem, STtraits, STalloc>& str,
    flag_type flags = ECMAScript);
template<class InIt>
    basic_regex& assign(InIt first, InIt last,
    flag_type flags = ECMAScript);

STtraits

Traits class for a string source.

STalloc

Allocator class for a string source.

InIt

Input iterator type for a range source.

right

Regex source to copy.

ptr

Pointer to beginning of sequence to copy.

flags

Syntax option flags to add while copying.

len/TD>

Length of sequence to copy.

str

String to copy.

first

Beginning of sequence to copy.

last

End of sequence to copy.

The member functions each replace the regular expression held by *this with the regular expression described by the operand sequence, then return *this.

 

// std_tr1__regex__basic_regex_assign.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    std::tr1::regex::value_type elem = 'x'; 
    std::tr1::regex::flag_type flag = std::tr1::regex::grep; 
 
    elem = elem;  // to quiet "unused" warnings 
    flag = flag; 
 
// constructors 
    std::tr1::regex rx0; 
    std::cout << "match(\"abc\", \"\") == " << std::boolalpha 
        << regex_match("abc", rx0) << std::endl; 
 
    std::tr1::regex rx1("abcd", std::tr1::regex::ECMAScript); 
    std::cout << "match(\"abc\", \"abcd\") == " << std::boolalpha 
        << regex_match("abc", rx1) << std::endl; 
 
    std::tr1::regex rx2("abcd", 3); 
    std::cout << "match(\"abc\", \"abc\") == " << std::boolalpha 
        << regex_match("abc", rx2) << std::endl; 
 
    std::tr1::regex rx3(rx2); 
    std::cout << "match(\"abc\", \"abc\") == " << std::boolalpha 
        << regex_match("abc", rx3) << std::endl; 
 
    std::string str("abcd"); 
    std::tr1::regex rx4(str); 
    std::cout << "match(string(\"abcd\"), \"abc\") == " << std::boolalpha 
        << regex_match("abc", rx4) << std::endl; 
 
    std::tr1::regex rx5(str.begin(), str.end() - 1); 
    std::cout << "match(string(\"abc\"), \"abc\") == " << std::boolalpha 
        << regex_match("abc", rx5) << std::endl; 
    std::cout << std::endl; 
 
// assignments 
    rx0 = "abc"; 
    rx0 = rx1; 
    rx0 = str; 
 
    rx0.assign("abcd", std::tr1::regex::ECMAScript); 
    rx0.assign("abcd", 3); 
    rx0.assign(rx1); 
    rx0.assign(str); 
    rx0.assign(str.begin(), str.end() - 1); 
 
    rx0.swap(rx1); 
 
// mark_count 
    std::cout << "\"abc\" mark_count == " 
        << std::tr1::regex("abc").mark_count() << std::endl; 
    std::cout << "\"(abc)\" mark_count == " 
        << std::tr1::regex("(abc)").mark_count() << std::endl; 
 
// locales 
    std::tr1::regex::locale_type loc = rx0.imbue(std::locale()); 
    std::cout << "getloc == imbued == " << std::boolalpha 
        << (loc == rx0.getloc()) << std::endl; 
 
    return (0); 
    } 
 
match("abc", "") == false match("abc", "abcd") == false match("abc", "abc") == true match("abc", "abc") == true match(string("abcd"), "abc") == false match(string("abc"), "abc") == true "abc" mark_count == 0 "(abc)" mark_count == 1 getloc == imbued == true

Header: <regex>

Namespace: std::tr1

Community Additions

ADD
Show:
© 2015 Microsoft