public member function
<regex>

std::basic_regex::operator=

(1)
basic_regex& operator= (const basic_regex& rgx);
(2)
basic_regex& operator= (basic_regex&& rgx) noexcept;
(3)
basic_regex& operator= (const charT* str);
(4)
template <class ST, class SA>
  basic_regex& operator= (const basic_string<charT,ST,SA>& str);
(5)
basic_regex& operator= (initializer_list<charT> il);
Assign regular expression
Assigns its argument as the new regular expression, overwriting any previous value.

With versions (1) and (2) the object acquires the syntax option flags of rgx.
Versions (3), (4), and (5) reset the flags to its default value: ECMAScript.

This member function behaves like the versions of regex::assign that only take one parameter. See regex::assign for options with multiple parameters (including setting different syntax option flags).

Parameters

rgx
Another regex object.
str
A string with the regular expression (the pattern).
charT is the first class template paramameter (the character type).
il
An initializer_list of characters. These objects are automatically constructed from initializer list declarators.

Return value

*this

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// basic_regex::operator=
// note: using regex, a standard alias of basic_regex<char>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string pattern ("six");
  std::regex first;
  std::regex second (pattern, std::regex::icase);

  first = second;              // copy assignment (flags preserved)
  second = "[0-9A-F]+";        // assigning string literal (flags reset)
  second = {'^','.'};          // assigning initializer list (flags reset)
  second = pattern;            // assigning string object (flags reset)

  std::string subject = "Sixty six";
  std::string replacement = "seven";

  std::cout << "first: " << std::regex_replace (subject, first, replacement);
  std::cout << std::endl;

  std::cout << "second: " << std::regex_replace (subject, second, replacement);
  std::cout << std::endl;

  return 0;
}


Output:
seventy seven
Sixty seven

See also