1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template <class traits, class charT>
12 // basic_string<charT>
13 // regex_replace(const charT* s,
14 // const basic_regex<charT, traits>& e,
16 // regex_constants::match_flag_type flags =
17 // regex_constants::match_default);
21 #include "test_macros.h"
26 std::regex
phone_numbers("\\d{3}-\\d{4}");
27 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
28 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
30 assert(r
== "123-555-1234, 123-555-2345, 123-555-3456");
33 std::regex
phone_numbers("\\d{3}-\\d{4}");
34 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
35 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
37 std::regex_constants::format_sed
);
38 assert(r
== "123-$555-1234, 123-$555-2345, 123-$555-3456");
41 std::regex
phone_numbers("\\d{3}-\\d{4}");
42 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
43 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
45 std::regex_constants::format_sed
);
46 assert(r
== "123-555-1234, 123-555-2345, 123-555-3456");
49 std::regex
phone_numbers("\\d{3}-\\d{4}");
50 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
51 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
53 std::regex_constants::format_no_copy
);
54 assert(r
== "123-555-1234123-555-2345123-555-3456");
57 std::regex
phone_numbers("\\d{3}-\\d{4}");
58 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
59 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
61 std::regex_constants::format_first_only
);
62 assert(r
== "123-555-1234, 555-2345, 555-3456");
65 std::regex
phone_numbers("\\d{3}-\\d{4}");
66 const char phone_book
[] = "555-1234, 555-2345, 555-3456";
67 std::string r
= std::regex_replace(phone_book
, phone_numbers
,
69 std::regex_constants::format_first_only
|
70 std::regex_constants::format_no_copy
);
71 assert(r
== "123-555-1234");