From Jason Turner

[re]

Large diff (128.4 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpb209zux6/{from.md → to.md} +610 -602
tmp/tmpb209zux6/{from.md → to.md} RENAMED
@@ -4,17 +4,17 @@
4
 
5
  This Clause describes components that C++programs may use to perform
6
  operations involving regular expression matching and searching.
7
 
8
  The following subclauses describe a basic regular expression class
9
- template and its traits that can handle char-like template arguments,
10
- two specializations of this class template that handle sequences of
11
- `char` and `wchar_t`, a class template that holds the result of a
12
- regular expression match, a series of algorithms that allow a character
13
- sequence to be operated upon by a regular expression, and two iterator
14
- types for enumerating regular expression matches, as described in Table 
15
- [[tab:re.lib.summary]].
16
 
17
  **Table: Regular expressions library summary** <a id="tab:re.lib.summary">[tab:re.lib.summary]</a>
18
 
19
  | Subclause | | Header |
20
  | --------------- | --------------------------- | --------- |
@@ -72,19 +72,21 @@ a pattern that selects specific strings from a set of character strings.
72
  a subset of a regular expression that has been marked by parenthesis.
73
 
74
  ## Requirements <a id="re.req">[[re.req]]</a>
75
 
76
  This subclause defines requirements on classes representing regular
77
- expression traits. The class template `regex_traits`, defined in Clause 
78
- [[re.traits]], satisfies these requirements.
 
 
79
 
80
  The class template `basic_regex`, defined in Clause  [[re.regex]], needs
81
  a set of related types and functions to complete the definition of its
82
  semantics. These types and functions are provided as a set of member
83
- typedefs and functions in the template parameter `traits` used by the
84
- `basic_regex` class template. This subclause defines the semantics of
85
- these members.
86
 
87
  To specialize class template `basic_regex` for a character container
88
  `CharT` and its related regular expression traits class `Traits`, use
89
  `basic_regex<CharT, Traits>`.
90
 
@@ -97,53 +99,56 @@ iterators ([[input.iterators]]); `F1` and `F2` are forward iterators (
97
  object of type `X::string_type`; `cs` is an object of type
98
  `const X::string_type`; `b` is a value of type `bool`; `I` is a value of
99
  type `int`; `cl` is an object of type `X::char_class_type`, and `loc` is
100
  an object of type `X::locale_type`.
101
 
102
- Class template `regex_traits` satisfies the requirements for a regular
103
- expression traits class when it is specialized for `char` or `wchar_t`.
104
- This class template is described in the header `<regex>`, and is
105
- described in Clause  [[re.traits]].
 
 
106
 
107
  ## Header `<regex>` synopsis <a id="re.syn">[[re.syn]]</a>
108
 
109
  ``` cpp
110
  #include <initializer_list>
111
 
112
  namespace std {
113
-
114
- // [re.const], regex constants:
115
  namespace regex_constants {
116
- enum error_type;
117
- } // namespace regex_constants
 
 
118
 
119
- // [re.badexp], class regex_error:
120
  class regex_error;
121
 
122
- // [re.traits], class template regex_traits:
123
  template <class charT> struct regex_traits;
124
 
125
- // [re.regex], class template basic_regex:
126
  template <class charT, class traits = regex_traits<charT>> class basic_regex;
127
 
128
- typedef basic_regex<char> regex;
129
- typedef basic_regex<wchar_t> wregex;
130
 
131
- // [re.regex.swap], basic_regex swap:
132
  template <class charT, class traits>
133
  void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
134
 
135
- // [re.submatch], class template sub_match:
136
  template <class BidirectionalIterator>
137
  class sub_match;
138
 
139
- typedef sub_match<const char*> csub_match;
140
- typedef sub_match<const wchar_t*> wcsub_match;
141
- typedef sub_match<string::const_iterator> ssub_match;
142
- typedef sub_match<wstring::const_iterator> wssub_match;
143
 
144
- // [re.submatch.op], sub_match non-member operators:
145
  template <class BiIter>
146
  bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
147
  template <class BiIter>
148
  bool operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
149
  template <class BiIter>
@@ -153,339 +158,309 @@ namespace std {
153
  template <class BiIter>
154
  bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
155
  template <class BiIter>
156
  bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
157
 
158
-
159
  template <class BiIter, class ST, class SA>
160
  bool operator==(
161
- const basic_string<
162
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
163
  const sub_match<BiIter>& rhs);
164
  template <class BiIter, class ST, class SA>
165
  bool operator!=(
166
- const basic_string<
167
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
168
  const sub_match<BiIter>& rhs);
169
  template <class BiIter, class ST, class SA>
170
  bool operator<(
171
- const basic_string<
172
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
173
  const sub_match<BiIter>& rhs);
174
  template <class BiIter, class ST, class SA>
175
  bool operator>(
176
- const basic_string<
177
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
178
  const sub_match<BiIter>& rhs);
179
  template <class BiIter, class ST, class SA>
180
  bool operator>=(
181
- const basic_string<
182
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
183
  const sub_match<BiIter>& rhs);
184
  template <class BiIter, class ST, class SA>
185
  bool operator<=(
186
- const basic_string<
187
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
188
  const sub_match<BiIter>& rhs);
189
 
190
  template <class BiIter, class ST, class SA>
191
  bool operator==(
192
  const sub_match<BiIter>& lhs,
193
- const basic_string<
194
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
195
  template <class BiIter, class ST, class SA>
196
  bool operator!=(
197
  const sub_match<BiIter>& lhs,
198
- const basic_string<
199
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
200
  template <class BiIter, class ST, class SA>
201
  bool operator<(
202
  const sub_match<BiIter>& lhs,
203
- const basic_string<
204
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
205
  template <class BiIter, class ST, class SA>
206
  bool operator>(
207
  const sub_match<BiIter>& lhs,
208
- const basic_string<
209
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
210
  template <class BiIter, class ST, class SA>
211
  bool operator>=(
212
  const sub_match<BiIter>& lhs,
213
- const basic_string<
214
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
215
  template <class BiIter, class ST, class SA>
216
  bool operator<=(
217
  const sub_match<BiIter>& lhs,
218
- const basic_string<
219
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
220
 
221
  template <class BiIter>
222
- bool operator==(typename iterator_traits<BiIter>::value_type const* lhs,
223
  const sub_match<BiIter>& rhs);
224
  template <class BiIter>
225
- bool operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
226
  const sub_match<BiIter>& rhs);
227
  template <class BiIter>
228
- bool operator<(typename iterator_traits<BiIter>::value_type const* lhs,
229
  const sub_match<BiIter>& rhs);
230
  template <class BiIter>
231
- bool operator>(typename iterator_traits<BiIter>::value_type const* lhs,
232
  const sub_match<BiIter>& rhs);
233
  template <class BiIter>
234
- bool operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
235
  const sub_match<BiIter>& rhs);
236
  template <class BiIter>
237
- bool operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
238
  const sub_match<BiIter>& rhs);
239
 
240
  template <class BiIter>
241
  bool operator==(const sub_match<BiIter>& lhs,
242
- typename iterator_traits<BiIter>::value_type const* rhs);
243
  template <class BiIter>
244
  bool operator!=(const sub_match<BiIter>& lhs,
245
- typename iterator_traits<BiIter>::value_type const* rhs);
246
  template <class BiIter>
247
  bool operator<(const sub_match<BiIter>& lhs,
248
- typename iterator_traits<BiIter>::value_type const* rhs);
249
  template <class BiIter>
250
  bool operator>(const sub_match<BiIter>& lhs,
251
- typename iterator_traits<BiIter>::value_type const* rhs);
252
  template <class BiIter>
253
  bool operator>=(const sub_match<BiIter>& lhs,
254
- typename iterator_traits<BiIter>::value_type const* rhs);
255
  template <class BiIter>
256
  bool operator<=(const sub_match<BiIter>& lhs,
257
- typename iterator_traits<BiIter>::value_type const* rhs);
258
 
259
  template <class BiIter>
260
- bool operator==(typename iterator_traits<BiIter>::value_type const& lhs,
261
  const sub_match<BiIter>& rhs);
262
  template <class BiIter>
263
- bool operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
264
  const sub_match<BiIter>& rhs);
265
  template <class BiIter>
266
- bool operator<(typename iterator_traits<BiIter>::value_type const& lhs,
267
  const sub_match<BiIter>& rhs);
268
  template <class BiIter>
269
- bool operator>(typename iterator_traits<BiIter>::value_type const& lhs,
270
  const sub_match<BiIter>& rhs);
271
  template <class BiIter>
272
- bool operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
273
  const sub_match<BiIter>& rhs);
274
  template <class BiIter>
275
- bool operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
276
  const sub_match<BiIter>& rhs);
277
 
278
  template <class BiIter>
279
  bool operator==(const sub_match<BiIter>& lhs,
280
- typename iterator_traits<BiIter>::value_type const& rhs);
281
  template <class BiIter>
282
  bool operator!=(const sub_match<BiIter>& lhs,
283
- typename iterator_traits<BiIter>::value_type const& rhs);
284
  template <class BiIter>
285
  bool operator<(const sub_match<BiIter>& lhs,
286
- typename iterator_traits<BiIter>::value_type const& rhs);
287
  template <class BiIter>
288
  bool operator>(const sub_match<BiIter>& lhs,
289
- typename iterator_traits<BiIter>::value_type const& rhs);
290
  template <class BiIter>
291
  bool operator>=(const sub_match<BiIter>& lhs,
292
- typename iterator_traits<BiIter>::value_type const& rhs);
293
  template <class BiIter>
294
  bool operator<=(const sub_match<BiIter>& lhs,
295
- typename iterator_traits<BiIter>::value_type const& rhs);
296
 
297
  template <class charT, class ST, class BiIter>
298
  basic_ostream<charT, ST>&
299
  operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
300
 
301
- // [re.results], class template match_results:
302
  template <class BidirectionalIterator,
303
  class Allocator = allocator<sub_match<BidirectionalIterator>>>
304
  class match_results;
305
 
306
- typedef match_results<const char*> cmatch;
307
- typedef match_results<const wchar_t*> wcmatch;
308
- typedef match_results<string::const_iterator> smatch;
309
- typedef match_results<wstring::const_iterator> wsmatch;
310
 
311
  // match_results comparisons
312
  template <class BidirectionalIterator, class Allocator>
313
  bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
314
  const match_results<BidirectionalIterator, Allocator>& m2);
315
  template <class BidirectionalIterator, class Allocator>
316
  bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
317
  const match_results<BidirectionalIterator, Allocator>& m2);
318
 
319
- // [re.results.swap], match_results swap:
320
  template <class BidirectionalIterator, class Allocator>
321
  void swap(match_results<BidirectionalIterator, Allocator>& m1,
322
  match_results<BidirectionalIterator, Allocator>& m2);
323
 
324
- // [re.alg.match], function template regex_match:
325
- template <class BidirectionalIterator, class Allocator,
326
- class charT, class traits>
327
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
328
  match_results<BidirectionalIterator, Allocator>& m,
329
  const basic_regex<charT, traits>& e,
330
- regex_constants::match_flag_type flags =
331
- regex_constants::match_default);
332
  template <class BidirectionalIterator, class charT, class traits>
333
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
334
  const basic_regex<charT, traits>& e,
335
- regex_constants::match_flag_type flags =
336
- regex_constants::match_default);
337
  template <class charT, class Allocator, class traits>
338
  bool regex_match(const charT* str, match_results<const charT*, Allocator>& m,
339
  const basic_regex<charT, traits>& e,
340
- regex_constants::match_flag_type flags =
341
- regex_constants::match_default);
342
  template <class ST, class SA, class Allocator, class charT, class traits>
343
  bool regex_match(const basic_string<charT, ST, SA>& s,
344
- match_results<
345
- typename basic_string<charT, ST, SA>::const_iterator,
346
  Allocator>& m,
347
  const basic_regex<charT, traits>& e,
348
- regex_constants::match_flag_type flags =
349
- regex_constants::match_default);
350
  template <class ST, class SA, class Allocator, class charT, class traits>
351
  bool regex_match(const basic_string<charT, ST, SA>&&,
352
- match_results<
353
- typename basic_string<charT, ST, SA>::const_iterator,
354
  Allocator>&,
355
  const basic_regex<charT, traits>&,
356
- regex_constants::match_flag_type =
357
- regex_constants::match_default) = delete;
358
  template <class charT, class traits>
359
  bool regex_match(const charT* str,
360
  const basic_regex<charT, traits>& e,
361
- regex_constants::match_flag_type flags =
362
- regex_constants::match_default);
363
  template <class ST, class SA, class charT, class traits>
364
  bool regex_match(const basic_string<charT, ST, SA>& s,
365
  const basic_regex<charT, traits>& e,
366
- regex_constants::match_flag_type flags =
367
- regex_constants::match_default);
368
 
369
- // [re.alg.search], function template regex_search:
370
- template <class BidirectionalIterator, class Allocator,
371
- class charT, class traits>
372
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
373
  match_results<BidirectionalIterator, Allocator>& m,
374
  const basic_regex<charT, traits>& e,
375
- regex_constants::match_flag_type flags =
376
- regex_constants::match_default);
377
  template <class BidirectionalIterator, class charT, class traits>
378
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
379
  const basic_regex<charT, traits>& e,
380
- regex_constants::match_flag_type flags =
381
- regex_constants::match_default);
382
  template <class charT, class Allocator, class traits>
383
  bool regex_search(const charT* str,
384
  match_results<const charT*, Allocator>& m,
385
  const basic_regex<charT, traits>& e,
386
- regex_constants::match_flag_type flags =
387
- regex_constants::match_default);
388
  template <class charT, class traits>
389
  bool regex_search(const charT* str,
390
  const basic_regex<charT, traits>& e,
391
- regex_constants::match_flag_type flags =
392
- regex_constants::match_default);
393
  template <class ST, class SA, class charT, class traits>
394
  bool regex_search(const basic_string<charT, ST, SA>& s,
395
  const basic_regex<charT, traits>& e,
396
- regex_constants::match_flag_type flags =
397
- regex_constants::match_default);
398
  template <class ST, class SA, class Allocator, class charT, class traits>
399
  bool regex_search(const basic_string<charT, ST, SA>& s,
400
- match_results<
401
- typename basic_string<charT, ST, SA>::const_iterator,
402
  Allocator>& m,
403
  const basic_regex<charT, traits>& e,
404
- regex_constants::match_flag_type flags =
405
- regex_constants::match_default);
406
  template <class ST, class SA, class Allocator, class charT, class traits>
407
  bool regex_search(const basic_string<charT, ST, SA>&&,
408
- match_results<
409
- typename basic_string<charT, ST, SA>::const_iterator,
410
  Allocator>&,
411
  const basic_regex<charT, traits>&,
412
- regex_constants::match_flag_type =
413
- regex_constants::match_default) = delete;
414
 
415
- // [re.alg.replace], function template regex_replace:
416
  template <class OutputIterator, class BidirectionalIterator,
417
  class traits, class charT, class ST, class SA>
418
  OutputIterator
419
  regex_replace(OutputIterator out,
420
  BidirectionalIterator first, BidirectionalIterator last,
421
  const basic_regex<charT, traits>& e,
422
  const basic_string<charT, ST, SA>& fmt,
423
- regex_constants::match_flag_type flags =
424
- regex_constants::match_default);
425
- template <class OutputIterator, class BidirectionalIterator,
426
- class traits, class charT>
427
  OutputIterator
428
  regex_replace(OutputIterator out,
429
  BidirectionalIterator first, BidirectionalIterator last,
430
  const basic_regex<charT, traits>& e,
431
  const charT* fmt,
432
- regex_constants::match_flag_type flags =
433
- regex_constants::match_default);
434
- template <class traits, class charT, class ST, class SA,
435
- class FST, class FSA>
436
  basic_string<charT, ST, SA>
437
  regex_replace(const basic_string<charT, ST, SA>& s,
438
  const basic_regex<charT, traits>& e,
439
  const basic_string<charT, FST, FSA>& fmt,
440
- regex_constants::match_flag_type flags =
441
- regex_constants::match_default);
442
  template <class traits, class charT, class ST, class SA>
443
  basic_string<charT, ST, SA>
444
  regex_replace(const basic_string<charT, ST, SA>& s,
445
  const basic_regex<charT, traits>& e,
446
  const charT* fmt,
447
- regex_constants::match_flag_type flags =
448
- regex_constants::match_default);
449
  template <class traits, class charT, class ST, class SA>
450
  basic_string<charT>
451
  regex_replace(const charT* s,
452
  const basic_regex<charT, traits>& e,
453
  const basic_string<charT, ST, SA>& fmt,
454
- regex_constants::match_flag_type flags =
455
- regex_constants::match_default);
456
  template <class traits, class charT>
457
  basic_string<charT>
458
  regex_replace(const charT* s,
459
  const basic_regex<charT, traits>& e,
460
  const charT* fmt,
461
- regex_constants::match_flag_type flags =
462
- regex_constants::match_default);
463
 
464
- // [re.regiter], class template regex_iterator:
465
  template <class BidirectionalIterator,
466
- class charT = typename iterator_traits<
467
- BidirectionalIterator>::value_type,
468
  class traits = regex_traits<charT>>
469
  class regex_iterator;
470
 
471
- typedef regex_iterator<const char*> cregex_iterator;
472
- typedef regex_iterator<const wchar_t*> wcregex_iterator;
473
- typedef regex_iterator<string::const_iterator> sregex_iterator;
474
- typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
475
 
476
- // [re.tokiter], class template regex_token_iterator:
477
  template <class BidirectionalIterator,
478
- class charT = typename iterator_traits<
479
- BidirectionalIterator>::value_type,
480
  class traits = regex_traits<charT>>
481
  class regex_token_iterator;
482
 
483
- typedef regex_token_iterator<const char*> cregex_token_iterator;
484
- typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
485
- typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
486
- typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
 
 
 
 
 
 
 
 
 
 
 
 
487
  }
488
  ```
489
 
490
  ## Namespace `std::regex_constants` <a id="re.const">[[re.const]]</a>
491
 
@@ -495,30 +470,29 @@ the regular expression library. This namespace provides three types,
495
  several constants of these types.
496
 
497
  ### Bitmask type `syntax_option_type` <a id="re.synopt">[[re.synopt]]</a>
498
 
499
  ``` cpp
500
- namespace std {
501
- namespace regex_constants {
502
- typedef T1 syntax_option_type;
503
- constexpr syntax_option_type icase = unspecified;
504
- constexpr syntax_option_type nosubs = unspecified;
505
- constexpr syntax_option_type optimize = unspecified;
506
- constexpr syntax_option_type collate = unspecified;
507
- constexpr syntax_option_type ECMAScript = unspecified;
508
- constexpr syntax_option_type basic = unspecified;
509
- constexpr syntax_option_type extended = unspecified;
510
- constexpr syntax_option_type awk = unspecified;
511
- constexpr syntax_option_type grep = unspecified;
512
- constexpr syntax_option_type egrep = unspecified;
513
- }
514
  }
515
  ```
516
 
517
- The type `syntax_option_type` is an implementation-defined bitmask
518
  type ([[bitmask.types]]). Setting its elements has the effects listed
519
- in table  [[tab:re:syntaxoption]]. A valid value of type
520
  `syntax_option_type` shall have at most one of the grammar elements
521
  `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep`, set. If no
522
  grammar element is set, the default grammar is `ECMAScript`.
523
 
524
  **Table: `syntax_option_type` effects** <a id="tab:re:syntaxoption">[tab:re:syntaxoption]</a>
@@ -533,38 +507,37 @@ grammar element is set, the default grammar is `ECMAScript`.
533
  | % `basic` | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions. \indextext{POSIX!regular expressions}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{basic}}% |
534
  | % `extended` | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions. \indextext{POSIX!extended regular expressions}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{extended}}% |
535
  | % `awk` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX. \indextext{\idxcode{awk}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{awk}}% |
536
  | % `grep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX. \indextext{\idxcode{grep}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{grep}}% |
537
  | % `egrep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX. \indextext{\idxcode{egrep}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{egrep}}% |
 
538
 
539
 
540
- ### Bitmask type `regex_constants::match_flag_type` <a id="re.matchflag">[[re.matchflag]]</a>
541
 
542
  ``` cpp
543
- namespace std {
544
- namespace regex_constants{
545
- typedef T2 match_flag_type;
546
- constexpr match_flag_type match_default = {};
547
- constexpr match_flag_type match_not_bol = unspecified;
548
- constexpr match_flag_type match_not_eol = unspecified;
549
- constexpr match_flag_type match_not_bow = unspecified;
550
- constexpr match_flag_type match_not_eow = unspecified;
551
- constexpr match_flag_type match_any = unspecified;
552
- constexpr match_flag_type match_not_null = unspecified;
553
- constexpr match_flag_type match_continuous = unspecified;
554
- constexpr match_flag_type match_prev_avail = unspecified;
555
- constexpr match_flag_type format_default = {};
556
- constexpr match_flag_type format_sed = unspecified;
557
- constexpr match_flag_type format_no_copy = unspecified;
558
- constexpr match_flag_type format_first_only = unspecified;
559
- }
560
  }
561
  ```
562
 
563
- The type `regex_constants::match_flag_type` is an implementation-defined
564
- bitmask type ([[bitmask.types]]). The constants of that type, except
565
- for `match_default` and `format_default`, are bitmask elements. The
566
  `match_default` and `format_default` constants are empty bitmasks.
567
  Matching a regular expression against a sequence of characters
568
  \[`first`, `last`) proceeds according to the rules of the grammar
569
  specified for the regular expression object, modified according to the
570
  effects listed in Table  [[tab:re:matchflag]] for any bitmask elements
@@ -580,37 +553,35 @@ set.
580
  | % \indexlibrary{\idxcode{match_not_bow}}% `match_not_bow` | The expression \verb|"b"| shall not match the sub-sequence {[}`first`, `first`{)}. |
581
  | % \indexlibrary{\idxcode{match_not_eow}}% `match_not_eow` | The expression \verb|"b"| shall not match the sub-sequence {[}`last`, `last`{)}. |
582
  | % \indexlibrary{\idxcode{match_any}}% `match_any` | If more than one match is possible then any match is an acceptable result. |
583
  | % \indexlibrary{\idxcode{match_not_null}}% `match_not_null` | The expression shall not match an empty sequence. |
584
  | % \indexlibrary{\idxcode{match_continuous}}% `match_continuous` | The expression shall only match a sub-sequence that begins at `first`. |
585
- | % \indexlibrary{\idxcode{match_prev_avail}}% `match_prev_avail` | \verb!--first! is a valid iterator position. When this flag is set the flags match_not_bol and match_not_bow shall be ignored by the regular expression algorithms~ [[re.alg]] and iterators~ [[re.iter]]. |
586
  | % \indexlibrary{\idxcode{format_default}}% `format_default` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the ECMAScript replace function in ECMA-262, part 15.5.4.11 String.prototype.replace. In addition, during search and replace operations all non-overlapping occurrences of the regular expression shall be located and replaced, and sections of the input that did not match the expression shall be copied unchanged to the output string. |
587
  | % \indexlibrary{\idxcode{format_sed}}% `format_sed` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the sed utility in POSIX. |
588
  | % \indexlibrary{\idxcode{format_no_copy}}% `format_no_copy` | During a search and replace operation, sections of the character container sequence being searched that do not match the regular expression shall not be copied to the output string. |
589
  | % \indexlibrary{\idxcode{format_first_only}}% `format_first_only` | When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced. |
590
 
591
 
592
  ### Implementation-defined `error_type` <a id="re.err">[[re.err]]</a>
593
 
594
  ``` cpp
595
- namespace std {
596
- namespace regex_constants {
597
- typedef T3 error_type;
598
- constexpr error_type error_collate = unspecified;
599
- constexpr error_type error_ctype = unspecified;
600
- constexpr error_type error_escape = unspecified;
601
- constexpr error_type error_backref = unspecified;
602
- constexpr error_type error_brack = unspecified;
603
- constexpr error_type error_paren = unspecified;
604
- constexpr error_type error_brace = unspecified;
605
- constexpr error_type error_badbrace = unspecified;
606
- constexpr error_type error_range = unspecified;
607
- constexpr error_type error_space = unspecified;
608
- constexpr error_type error_badrepeat = unspecified;
609
- constexpr error_type error_complexity = unspecified;
610
- constexpr error_type error_stack = unspecified;
611
- }
612
  }
613
  ```
614
 
615
  The type `error_type` is an *implementation-defined* enumerated type (
616
  [[enumerated.types]]). Values of type `error_type` represent the error
@@ -636,11 +607,11 @@ conditions described in Table  [[tab:re:errortype]]:
636
 
637
 
638
  ## Class `regex_error` <a id="re.badexp">[[re.badexp]]</a>
639
 
640
  ``` cpp
641
- class regex_error : public std::runtime_error {
642
  public:
643
  explicit regex_error(regex_constants::error_type ecode);
644
  regex_constants::error_type code() const;
645
  };
646
  ```
@@ -652,11 +623,11 @@ to report errors from the regular expression library.
652
  regex_error(regex_constants::error_type ecode);
653
  ```
654
 
655
  *Effects:* Constructs an object of class `regex_error`.
656
 
657
- : `ecode == code()`
658
 
659
  ``` cpp
660
  regex_constants::error_type code() const;
661
  ```
662
 
@@ -666,18 +637,17 @@ regex_constants::error_type code() const;
666
 
667
  ``` cpp
668
  namespace std {
669
  template <class charT>
670
  struct regex_traits {
671
- public:
672
- typedef charT char_type;
673
- typedef std::basic_string<char_type> string_type;
674
- typedef std::locale locale_type;
675
- typedef {bitmask_type} char_class_type;
676
 
677
  regex_traits();
678
- static std::size_t length(const char_type* p);
679
  charT translate(charT c) const;
680
  charT translate_nocase(charT c) const;
681
  template <class ForwardIterator>
682
  string_type transform(ForwardIterator first, ForwardIterator last) const;
683
  template <class ForwardIterator>
@@ -700,28 +670,28 @@ namespace std {
700
  The specializations `regex_traits<char>` and `regex_traits<wchar_t>`
701
  shall be valid and shall satisfy the requirements for a regular
702
  expression traits class ([[re.req]]).
703
 
704
  ``` cpp
705
- typedef bitmask_type char_class_type;
706
  ```
707
 
708
  The type `char_class_type` is used to represent a character
709
  classification and is capable of holding an implementation specific set
710
  returned by `lookup_classname`.
711
 
712
  ``` cpp
713
- static std::size_t length(const char_type* p);
714
  ```
715
 
716
- *Returns:* `char_traits<charT>::length(p);`
717
 
718
  ``` cpp
719
  charT translate(charT c) const;
720
  ```
721
 
722
- *Returns:* `(c)`.
723
 
724
  ``` cpp
725
  charT translate_nocase(charT c) const;
726
  ```
727
 
@@ -730,11 +700,11 @@ charT translate_nocase(charT c) const;
730
  ``` cpp
731
  template <class ForwardIterator>
732
  string_type transform(ForwardIterator first, ForwardIterator last) const;
733
  ```
734
 
735
- *Effects:*
736
 
737
  ``` cpp
738
  string_type str(first, last);
739
  return use_facet<collate<charT>>(
740
  getloc()).transform(&*str.begin(), &*str.begin() + str.length());
@@ -743,14 +713,18 @@ return use_facet<collate<charT> >(
743
  ``` cpp
744
  template <class ForwardIterator>
745
  string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
746
  ```
747
 
748
- *Effects:* if
749
- `typeid(use_facet<collate<charT> >) == typeid(collate_byname<charT>)`
 
 
 
 
750
  and the form of the sort key returned by
751
- `collate_byname<charT> ``transform(first, last)` is known and can be
752
  converted into a primary sort key then returns that key, otherwise
753
  returns an empty string.
754
 
755
  ``` cpp
756
  template <class ForwardIterator>
@@ -768,16 +742,17 @@ template <class ForwardIterator>
768
  ForwardIterator first, ForwardIterator last, bool icase = false) const;
769
  ```
770
 
771
  *Returns:* an unspecified value that represents the character
772
  classification named by the character sequence designated by the
773
- iterator range \[`first`, `last`). If the parameter `icase` is true then
774
- the returned mask identifies the character classification without regard
775
- to the case of the characters being matched, otherwise it does honor the
776
- case of the characters being matched.[^1] The value returned shall be
777
- independent of the case of the characters in the character sequence. If
778
- the name is not recognized then returns `char_class_type()`.
 
779
 
780
  *Remarks:* For `regex_traits<char>`, at least the narrow character names
781
  in Table  [[tab:re.traits.classnames]] shall be recognized. For
782
  `regex_traits<wchar_t>`, at least the wide character names in
783
  Table  [[tab:re.traits.classnames]] shall be recognized.
@@ -787,11 +762,11 @@ bool isctype(charT c, char_class_type f) const;
787
  ```
788
 
789
  *Effects:* Determines if the character `c` is a member of the character
790
  classification represented by `f`.
791
 
792
- *Returns:* Given the following function prototype:
793
 
794
  ``` cpp
795
  // for exposition only
796
  template<class C>
797
  ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
@@ -808,60 +783,69 @@ const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
808
  if (ct.is(m, c)) {
809
  return true;
810
  } else if (c == ct.widen('_')) {
811
  charT w[1] = { ct.widen('w') };
812
  char_class_type x = lookup_classname(w, w+1);
813
-
814
  return (f&x) == x;
815
  } else {
816
  return false;
817
  }
818
  ```
819
 
 
 
820
  ``` cpp
821
  regex_traits<char> t;
822
  string d("d");
823
  string u("upper");
824
  regex_traits<char>::char_class_type f;
825
  f = t.lookup_classname(d.begin(), d.end());
826
  f |= t.lookup_classname(u.begin(), u.end());
827
  ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
828
  ```
829
 
 
 
 
 
830
  ``` cpp
831
  regex_traits<char> t;
832
  string w("w");
833
  regex_traits<char>::char_class_type f;
834
  f = t.lookup_classname(w.begin(), w.end());
835
  t.isctype('A', f); // returns true
836
  t.isctype('_', f); // returns true
837
  t.isctype(' ', f); // returns false
838
  ```
839
 
 
 
840
  ``` cpp
841
  int value(charT ch, int radix) const;
842
  ```
843
 
844
- The value of *radix* shall be 8, 10, or 16.
845
 
846
- *Returns:* the value represented by the digit *ch* in base *radix* if
847
- the character *ch* is a valid digit in base *radix*; otherwise returns
848
- -1.
849
 
850
  ``` cpp
851
  locale_type imbue(locale_type loc);
852
  ```
853
 
854
- *Effects:* Imbues `this` with a copy of the locale `loc`. Calling
855
- `imbue` with a different locale than the one currently in use
856
- invalidates all cached data held by `*this`.
 
 
857
 
858
  *Returns:* if no locale has been previously imbued then a copy of the
859
  global locale in effect at the time of construction of `*this`,
860
  otherwise a copy of the last argument passed to `imbue`.
861
 
862
- `getloc() == loc`.
863
 
864
  ``` cpp
865
  locale_type getloc() const;
866
  ```
867
 
@@ -901,30 +885,31 @@ allocated and freed as necessary by the member functions of class
901
 
902
  Objects of type specialization of `basic_regex` are responsible for
903
  converting the sequence of `charT` objects to an internal
904
  representation. It is not specified what form this representation takes,
905
  nor how it is accessed by algorithms that operate on regular
906
- expressions. Implementations will typically declare some function
907
- templates as friends of `basic_regex` to achieve this
 
 
908
 
909
  The functions described in this Clause report errors by throwing
910
  exceptions of type `regex_error`.
911
 
912
  ``` cpp
913
  namespace std {
914
- template <class charT,
915
- class traits = regex_traits<charT> >
916
  class basic_regex {
917
  public:
918
  // types:
919
- typedef charT value_type;
920
- typedef traits traits_type;
921
- typedef typename traits::string_type string_type;
922
- typedef regex_constants::syntax_option_type flag_type;
923
- typedef typename traits::locale_type locale_type;
924
 
925
- // [re.regex.const], constants:
926
  static constexpr regex_constants::syntax_option_type
927
  icase = regex_constants::icase;
928
  static constexpr regex_constants::syntax_option_type
929
  nosubs = regex_constants::nosubs;
930
  static constexpr regex_constants::syntax_option_type
@@ -941,88 +926,83 @@ namespace std {
941
  awk = regex_constants::awk;
942
  static constexpr regex_constants::syntax_option_type
943
  grep = regex_constants::grep;
944
  static constexpr regex_constants::syntax_option_type
945
  egrep = regex_constants::egrep;
 
 
946
 
947
- // [re.regex.construct], construct/copy/destroy:
948
  basic_regex();
949
- explicit basic_regex(const charT* p,
950
- flag_type f = regex_constants::ECMAScript);
951
  basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
952
  basic_regex(const basic_regex&);
953
  basic_regex(basic_regex&&) noexcept;
954
  template <class ST, class SA>
955
  explicit basic_regex(const basic_string<charT, ST, SA>& p,
956
  flag_type f = regex_constants::ECMAScript);
957
  template <class ForwardIterator>
958
  basic_regex(ForwardIterator first, ForwardIterator last,
959
  flag_type f = regex_constants::ECMAScript);
960
- basic_regex(initializer_list<charT>,
961
- flag_type = regex_constants::ECMAScript);
962
 
963
  ~basic_regex();
964
 
965
  basic_regex& operator=(const basic_regex&);
966
  basic_regex& operator=(basic_regex&&) noexcept;
967
  basic_regex& operator=(const charT* ptr);
968
  basic_regex& operator=(initializer_list<charT> il);
969
  template <class ST, class SA>
970
  basic_regex& operator=(const basic_string<charT, ST, SA>& p);
971
 
972
- // [re.regex.assign], assign:
973
  basic_regex& assign(const basic_regex& that);
974
  basic_regex& assign(basic_regex&& that) noexcept;
975
- basic_regex& assign(const charT* ptr,
976
- flag_type f = regex_constants::ECMAScript);
977
  basic_regex& assign(const charT* p, size_t len, flag_type f);
978
  template <class string_traits, class A>
979
  basic_regex& assign(const basic_string<charT, string_traits, A>& s,
980
  flag_type f = regex_constants::ECMAScript);
981
  template <class InputIterator>
982
  basic_regex& assign(InputIterator first, InputIterator last,
983
  flag_type f = regex_constants::ECMAScript);
984
  basic_regex& assign(initializer_list<charT>,
985
  flag_type = regex_constants::ECMAScript);
986
 
987
- // [re.regex.operations], const operations:
988
  unsigned mark_count() const;
989
  flag_type flags() const;
990
 
991
- // [re.regex.locale], locale:
992
  locale_type imbue(locale_type loc);
993
  locale_type getloc() const;
994
 
995
- // [re.regex.swap], swap:
996
  void swap(basic_regex&);
997
  };
 
 
 
 
 
998
  }
999
  ```
1000
 
1001
  ### `basic_regex` constants <a id="re.regex.const">[[re.regex.const]]</a>
1002
 
1003
  ``` cpp
1004
- static constexpr regex_constants::syntax_option_type
1005
- icase = regex_constants::icase;
1006
- static constexpr regex_constants::syntax_option_type
1007
- nosubs = regex_constants::nosubs;
1008
- static constexpr regex_constants::syntax_option_type
1009
- optimize = regex_constants::optimize;
1010
- static constexpr regex_constants::syntax_option_type
1011
- collate = regex_constants::collate;
1012
- static constexpr regex_constants::syntax_option_type
1013
- ECMAScript = regex_constants::ECMAScript;
1014
- static constexpr regex_constants::syntax_option_type
1015
- basic = regex_constants::basic;
1016
- static constexpr regex_constants::syntax_option_type
1017
- extended = regex_constants::extended;
1018
- static constexpr regex_constants::syntax_option_type
1019
- awk = regex_constants::awk;
1020
- static constexpr regex_constants::syntax_option_type
1021
- grep = regex_constants::grep;
1022
- static constexpr regex_constants::syntax_option_type
1023
- egrep = regex_constants::egrep;
1024
  ```
1025
 
1026
  The static constant members are provided as synonyms for the constants
1027
  declared in namespace `regex_constants`.
1028
 
@@ -1037,35 +1017,35 @@ match any character sequence.
1037
 
1038
  ``` cpp
1039
  explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
1040
  ```
1041
 
1042
- *Requires:* *p* shall not be a null pointer.
1043
 
1044
- *Throws:* `regex_error` if *p* is not a valid regular expression.
1045
 
1046
  *Effects:* Constructs an object of class `basic_regex`; the object’s
1047
  internal finite state machine is constructed from the regular expression
1048
  contained in the array of `charT` of length
1049
  `char_traits<charT>::length(p)` whose first element is designated by
1050
- *p*, and interpreted according to the flags *f*.
1051
 
1052
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1053
  number of marked sub-expressions within the expression.
1054
 
1055
  ``` cpp
1056
  basic_regex(const charT* p, size_t len, flag_type f);
1057
  ```
1058
 
1059
- *Requires:* *p* shall not be a null pointer.
1060
 
1061
- *Throws:* `regex_error` if *p* is not a valid regular expression.
1062
 
1063
  *Effects:* Constructs an object of class `basic_regex`; the object’s
1064
  internal finite state machine is constructed from the regular expression
1065
  contained in the sequence of characters \[`p`, `p+len`), and interpreted
1066
- according the flags specified in *f*.
1067
 
1068
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1069
  number of marked sub-expressions within the expression.
1070
 
1071
  ``` cpp
@@ -1120,79 +1100,81 @@ interpreted according to the flags specified in `f`.
1120
 
1121
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1122
  number of marked sub-expressions within the expression.
1123
 
1124
  ``` cpp
1125
- basic_regex(initializer_list<charT> il,
1126
- flag_type f = regex_constants::ECMAScript);
1127
  ```
1128
 
1129
  *Effects:* Same as `basic_regex(il.begin(), il.end(), f)`.
1130
 
1131
  ### `basic_regex` assign <a id="re.regex.assign">[[re.regex.assign]]</a>
1132
 
1133
  ``` cpp
1134
  basic_regex& operator=(const basic_regex& e);
1135
  ```
1136
 
1137
- *Effects:* returns `assign(e)`.
 
 
 
1138
 
1139
  ``` cpp
1140
  basic_regex& operator=(basic_regex&& e) noexcept;
1141
  ```
1142
 
1143
- *Effects:* returns `assign(std::move(e))`.
 
 
 
 
1144
 
1145
  ``` cpp
1146
  basic_regex& operator=(const charT* ptr);
1147
  ```
1148
 
1149
  *Requires:* `ptr` shall not be a null pointer.
1150
 
1151
- *Effects:* returns `assign(ptr)`.
1152
 
1153
  ``` cpp
1154
  basic_regex& operator=(initializer_list<charT> il);
1155
  ```
1156
 
1157
- *Effects:* returns `assign(il.begin(), il.end())`.
1158
 
1159
  ``` cpp
1160
  template <class ST, class SA>
1161
  basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1162
  ```
1163
 
1164
- *Effects:* returns `assign(p)`.
1165
 
1166
  ``` cpp
1167
  basic_regex& assign(const basic_regex& that);
1168
  ```
1169
 
1170
- *Effects:* copies `that` into `*this` and returns `*this`.
1171
 
1172
- *Postconditions:* `flags()` and `mark_count()` return `that.flags()` and
1173
- `that.mark_count()`, respectively.
1174
 
1175
  ``` cpp
1176
  basic_regex& assign(basic_regex&& that) noexcept;
1177
  ```
1178
 
1179
- *Effects:* move assigns from `that` into `*this` and returns `*this`.
1180
 
1181
- *Postconditions:* `flags()` and `mark_count()` return the values that
1182
- `that.flags()` and `that.mark_count()`, respectively, had before
1183
- assignment. `that` is in a valid state with unspecified value.
1184
 
1185
  ``` cpp
1186
  basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
1187
  ```
1188
 
1189
  *Returns:* `assign(string_type(ptr), f)`.
1190
 
1191
  ``` cpp
1192
- basic_regex& assign(const charT* ptr, size_t len,
1193
- flag_type f = regex_constants::ECMAScript);
1194
  ```
1195
 
1196
  *Returns:* `assign(string_type(ptr, len), f)`.
1197
 
1198
  ``` cpp
@@ -1254,32 +1236,32 @@ were passed to the object’s constructor or to the last call to `assign`.
1254
  ``` cpp
1255
  locale_type imbue(locale_type loc);
1256
  ```
1257
 
1258
  *Effects:* Returns the result of `traits_inst.imbue(loc)` where
1259
- `traits_inst` is a (default initialized) instance of the template type
1260
  argument `traits` stored within the object. After a call to `imbue` the
1261
  `basic_regex` object does not match any character sequence.
1262
 
1263
  ``` cpp
1264
  locale_type getloc() const;
1265
  ```
1266
 
1267
  *Effects:* Returns the result of `traits_inst.getloc()` where
1268
- `traits_inst` is a (default initialized) instance of the template
1269
  parameter `traits` stored within the object.
1270
 
1271
  ### `basic_regex` swap <a id="re.regex.swap">[[re.regex.swap]]</a>
1272
 
1273
  ``` cpp
1274
  void swap(basic_regex& e);
1275
  ```
1276
 
1277
  *Effects:* Swaps the contents of the two regular expressions.
1278
 
1279
- `*this` contains the regular expression that was in `e`, `e` contains
1280
- the regular expression that was in `*this`.
1281
 
1282
  *Complexity:* Constant time.
1283
 
1284
  ### `basic_regex` non-member functions <a id="re.regex.nonmemb">[[re.regex.nonmemb]]</a>
1285
 
@@ -1298,18 +1280,18 @@ Class template `sub_match` denotes the sequence of characters matched by
1298
  a particular marked sub-expression.
1299
 
1300
  ``` cpp
1301
  namespace std {
1302
  template <class BidirectionalIterator>
1303
- class sub_match : public std::pair<BidirectionalIterator, BidirectionalIterator> {
1304
  public:
1305
- typedef typename iterator_traits<BidirectionalIterator>::
1306
- value_type value_type;
1307
- typedef typename iterator_traits<BidirectionalIterator>::
1308
- difference_type difference_type;
1309
- typedef BidirectionalIterator iterator;
1310
- typedef basic_string<value_type> string_type;
1311
 
1312
  bool matched;
1313
 
1314
  constexpr sub_match();
1315
 
@@ -1335,23 +1317,23 @@ member `matched`.
1335
 
1336
  ``` cpp
1337
  difference_type length() const;
1338
  ```
1339
 
1340
- *Returns:* `(matched ? distance(first, second) : 0)`.
1341
 
1342
  ``` cpp
1343
  operator string_type() const;
1344
  ```
1345
 
1346
- *Returns:* `matched ? string_type(first, second) : string_type()`.
1347
 
1348
  ``` cpp
1349
  string_type str() const;
1350
  ```
1351
 
1352
- *Returns:* `matched ? string_type(first, second) : string_type()`.
1353
 
1354
  ``` cpp
1355
  int compare(const sub_match& s) const;
1356
  ```
1357
 
@@ -1414,391 +1396,405 @@ template <class BiIter>
1414
  *Returns:* `lhs.compare(rhs) > 0`.
1415
 
1416
  ``` cpp
1417
  template <class BiIter, class ST, class SA>
1418
  bool operator==(
1419
- const basic_string<
1420
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1421
  const sub_match<BiIter>& rhs);
1422
  ```
1423
 
1424
- *Returns:* `rhs.compare(lhs.c_str()) == 0`.
 
 
 
 
1425
 
1426
  ``` cpp
1427
  template <class BiIter, class ST, class SA>
1428
  bool operator!=(
1429
- const basic_string<
1430
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1431
  const sub_match<BiIter>& rhs);
1432
  ```
1433
 
1434
  *Returns:* `!(lhs == rhs)`.
1435
 
1436
  ``` cpp
1437
  template <class BiIter, class ST, class SA>
1438
  bool operator<(
1439
- const basic_string<
1440
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1441
  const sub_match<BiIter>& rhs);
1442
  ```
1443
 
1444
- *Returns:* `rhs.compare(lhs.c_str()) > 0`.
 
 
 
 
1445
 
1446
  ``` cpp
1447
  template <class BiIter, class ST, class SA>
1448
  bool operator>(
1449
- const basic_string<
1450
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1451
  const sub_match<BiIter>& rhs);
1452
  ```
1453
 
1454
  *Returns:* `rhs < lhs`.
1455
 
1456
  ``` cpp
1457
  template <class BiIter, class ST, class SA>
1458
  bool operator>=(
1459
- const basic_string<
1460
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1461
  const sub_match<BiIter>& rhs);
1462
  ```
1463
 
1464
  *Returns:* `!(lhs < rhs)`.
1465
 
1466
  ``` cpp
1467
  template <class BiIter, class ST, class SA>
1468
  bool operator<=(
1469
- const basic_string<
1470
- typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
1471
  const sub_match<BiIter>& rhs);
1472
  ```
1473
 
1474
  *Returns:* `!(rhs < lhs)`.
1475
 
1476
  ``` cpp
1477
  template <class BiIter, class ST, class SA>
1478
- bool operator==(const sub_match<BiIter>& lhs,
1479
- const basic_string<
1480
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1481
  ```
1482
 
1483
- *Returns:* `lhs.compare(rhs.c_str()) == 0`.
 
 
 
 
1484
 
1485
  ``` cpp
1486
  template <class BiIter, class ST, class SA>
1487
- bool operator!=(const sub_match<BiIter>& lhs,
1488
- const basic_string<
1489
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1490
  ```
1491
 
1492
  *Returns:* `!(lhs == rhs)`.
1493
 
1494
  ``` cpp
1495
  template <class BiIter, class ST, class SA>
1496
- bool operator<(const sub_match<BiIter>& lhs,
1497
- const basic_string<
1498
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1499
  ```
1500
 
1501
- *Returns:* `lhs.compare(rhs.c_str()) < 0`.
 
 
 
 
1502
 
1503
  ``` cpp
1504
  template <class BiIter, class ST, class SA>
1505
- bool operator>(const sub_match<BiIter>& lhs,
1506
- const basic_string<
1507
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1508
  ```
1509
 
1510
  *Returns:* `rhs < lhs`.
1511
 
1512
  ``` cpp
1513
  template <class BiIter, class ST, class SA>
1514
- bool operator>=(const sub_match<BiIter>& lhs,
1515
- const basic_string<
1516
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1517
  ```
1518
 
1519
  *Returns:* `!(lhs < rhs)`.
1520
 
1521
  ``` cpp
1522
  template <class BiIter, class ST, class SA>
1523
- bool operator<=(const sub_match<BiIter>& lhs,
1524
- const basic_string<
1525
- typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1526
  ```
1527
 
1528
  *Returns:* `!(rhs < lhs)`.
1529
 
1530
  ``` cpp
1531
  template <class BiIter>
1532
- bool operator==(typename iterator_traits<BiIter>::value_type const* lhs,
1533
  const sub_match<BiIter>& rhs);
1534
  ```
1535
 
1536
  *Returns:* `rhs.compare(lhs) == 0`.
1537
 
1538
  ``` cpp
1539
  template <class BiIter>
1540
- bool operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
1541
  const sub_match<BiIter>& rhs);
1542
  ```
1543
 
1544
  *Returns:* `!(lhs == rhs)`.
1545
 
1546
  ``` cpp
1547
  template <class BiIter>
1548
- bool operator<(typename iterator_traits<BiIter>::value_type const* lhs,
1549
  const sub_match<BiIter>& rhs);
1550
  ```
1551
 
1552
  *Returns:* `rhs.compare(lhs) > 0`.
1553
 
1554
  ``` cpp
1555
  template <class BiIter>
1556
- bool operator>(typename iterator_traits<BiIter>::value_type const* lhs,
1557
  const sub_match<BiIter>& rhs);
1558
  ```
1559
 
1560
  *Returns:* `rhs < lhs`.
1561
 
1562
  ``` cpp
1563
  template <class BiIter>
1564
- bool operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
1565
  const sub_match<BiIter>& rhs);
1566
  ```
1567
 
1568
  *Returns:* `!(lhs < rhs)`.
1569
 
1570
  ``` cpp
1571
  template <class BiIter>
1572
- bool operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
1573
  const sub_match<BiIter>& rhs);
1574
  ```
1575
 
1576
  *Returns:* `!(rhs < lhs)`.
1577
 
1578
  ``` cpp
1579
  template <class BiIter>
1580
  bool operator==(const sub_match<BiIter>& lhs,
1581
- typename iterator_traits<BiIter>::value_type const* rhs);
1582
  ```
1583
 
1584
  *Returns:* `lhs.compare(rhs) == 0`.
1585
 
1586
  ``` cpp
1587
  template <class BiIter>
1588
  bool operator!=(const sub_match<BiIter>& lhs,
1589
- typename iterator_traits<BiIter>::value_type const* rhs);
1590
  ```
1591
 
1592
  *Returns:* `!(lhs == rhs)`.
1593
 
1594
  ``` cpp
1595
  template <class BiIter>
1596
  bool operator<(const sub_match<BiIter>& lhs,
1597
- typename iterator_traits<BiIter>::value_type const* rhs);
1598
  ```
1599
 
1600
  *Returns:* `lhs.compare(rhs) < 0`.
1601
 
1602
  ``` cpp
1603
  template <class BiIter>
1604
  bool operator>(const sub_match<BiIter>& lhs,
1605
- typename iterator_traits<BiIter>::value_type const* rhs);
1606
  ```
1607
 
1608
  *Returns:* `rhs < lhs`.
1609
 
1610
  ``` cpp
1611
  template <class BiIter>
1612
  bool operator>=(const sub_match<BiIter>& lhs,
1613
- typename iterator_traits<BiIter>::value_type const* rhs);
1614
  ```
1615
 
1616
  *Returns:* `!(lhs < rhs)`.
1617
 
1618
  ``` cpp
1619
  template <class BiIter>
1620
  bool operator<=(const sub_match<BiIter>& lhs,
1621
- typename iterator_traits<BiIter>::value_type const* rhs);
1622
  ```
1623
 
1624
  *Returns:* `!(rhs < lhs)`.
1625
 
1626
  ``` cpp
1627
  template <class BiIter>
1628
- bool operator==(typename iterator_traits<BiIter>::value_type const& lhs,
1629
  const sub_match<BiIter>& rhs);
1630
  ```
1631
 
1632
  *Returns:*
1633
  `rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) == 0`.
1634
 
1635
  ``` cpp
1636
  template <class BiIter>
1637
- bool operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
1638
  const sub_match<BiIter>& rhs);
1639
  ```
1640
 
1641
  *Returns:* `!(lhs == rhs)`.
1642
 
1643
  ``` cpp
1644
  template <class BiIter>
1645
- bool operator<(typename iterator_traits<BiIter>::value_type const& lhs,
1646
  const sub_match<BiIter>& rhs);
1647
  ```
1648
 
1649
  *Returns:*
1650
  `rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) > 0`.
1651
 
1652
  ``` cpp
1653
  template <class BiIter>
1654
- bool operator>(typename iterator_traits<BiIter>::value_type const& lhs,
1655
  const sub_match<BiIter>& rhs);
1656
  ```
1657
 
1658
  *Returns:* `rhs < lhs`.
1659
 
1660
  ``` cpp
1661
  template <class BiIter>
1662
- bool operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
1663
  const sub_match<BiIter>& rhs);
1664
  ```
1665
 
1666
  *Returns:* `!(lhs < rhs)`.
1667
 
1668
  ``` cpp
1669
  template <class BiIter>
1670
- bool operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
1671
  const sub_match<BiIter>& rhs);
1672
  ```
1673
 
1674
  *Returns:* `!(rhs < lhs)`.
1675
 
1676
  ``` cpp
1677
  template <class BiIter>
1678
  bool operator==(const sub_match<BiIter>& lhs,
1679
- typename iterator_traits<BiIter>::value_type const& rhs);
1680
  ```
1681
 
1682
  *Returns:*
1683
  `lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0`.
1684
 
1685
  ``` cpp
1686
  template <class BiIter>
1687
  bool operator!=(const sub_match<BiIter>& lhs,
1688
- typename iterator_traits<BiIter>::value_type const& rhs);
1689
  ```
1690
 
1691
  *Returns:* `!(lhs == rhs)`.
1692
 
1693
  ``` cpp
1694
  template <class BiIter>
1695
  bool operator<(const sub_match<BiIter>& lhs,
1696
- typename iterator_traits<BiIter>::value_type const& rhs);
1697
  ```
1698
 
1699
  *Returns:*
1700
  `lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) < 0`.
1701
 
1702
  ``` cpp
1703
  template <class BiIter>
1704
  bool operator>(const sub_match<BiIter>& lhs,
1705
- typename iterator_traits<BiIter>::value_type const& rhs);
1706
  ```
1707
 
1708
  *Returns:* `rhs < lhs`.
1709
 
1710
  ``` cpp
1711
  template <class BiIter>
1712
  bool operator>=(const sub_match<BiIter>& lhs,
1713
- typename iterator_traits<BiIter>::value_type const& rhs);
1714
  ```
1715
 
1716
  *Returns:* `!(lhs < rhs)`.
1717
 
1718
  ``` cpp
1719
  template <class BiIter>
1720
  bool operator<=(const sub_match<BiIter>& lhs,
1721
- typename iterator_traits<BiIter>::value_type const& rhs);
1722
  ```
1723
 
1724
  *Returns:* `!(rhs < lhs)`.
1725
 
1726
  ``` cpp
1727
  template <class charT, class ST, class BiIter>
1728
  basic_ostream<charT, ST>&
1729
  operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
1730
  ```
1731
 
1732
- *Returns:* `(os << m.str())`.
1733
 
1734
  ## Class template `match_results` <a id="re.results">[[re.results]]</a>
1735
 
1736
  Class template `match_results` denotes a collection of character
1737
  sequences representing the result of a regular expression match. Storage
1738
  for the collection is allocated and freed as necessary by the member
1739
  functions of class template `match_results`.
1740
 
1741
- The class template `match_results` shall satisfy the requirements of an
1742
- allocator-aware container and of a sequence container, as specified in 
1743
- [[sequence.reqmts]], except that only operations defined for
1744
- const-qualified sequence containers are supported.
 
 
1745
 
1746
  A default-constructed `match_results` object has no fully established
1747
  result state. A match result is *ready* when, as a consequence of a
1748
  completed regular expression match modifying such an object, its result
1749
  state becomes fully established. The effects of calling most member
1750
  functions from a `match_results` object that is not ready are undefined.
1751
 
1752
  The `sub_match` object stored at index 0 represents sub-expression 0,
1753
  i.e., the whole match. In this case the `sub_match` member `matched` is
1754
- always true. The `sub_match` object stored at index `n` denotes what
1755
  matched the marked sub-expression `n` within the matched expression. If
1756
  the sub-expression `n` participated in a regular expression match then
1757
- the `sub_match` member `matched` evaluates to true, and members `first`
1758
- and `second` denote the range of characters \[`first`, `second`) which
1759
- formed that match. Otherwise `matched` is false, and members `first` and
1760
- `second` point to the end of the sequence that was searched. The
1761
- `sub_match` objects representing different sub-expressions that did not
1762
- participate in a regular expression match need not be distinct.
 
 
1763
 
1764
  ``` cpp
1765
  namespace std {
1766
  template <class BidirectionalIterator,
1767
  class Allocator = allocator<sub_match<BidirectionalIterator>>>
1768
  class match_results {
1769
  public:
1770
- typedef sub_match<BidirectionalIterator> value_type;
1771
- typedef const value_type& const_reference;
1772
- typedef value_type& reference;
1773
- typedef {implementation-defined} const_iterator;
1774
- typedef const_iterator iterator;
1775
- typedef typename
1776
- iterator_traits<BidirectionalIterator>::difference_type difference_type;
1777
- typedef typename allocator_traits<Allocator>::size_type size_type;
1778
- typedef Allocator allocator_type;
1779
- typedef typename iterator_traits<BidirectionalIterator>::
1780
- value_type char_type;
1781
- typedef basic_string<char_type> string_type;
1782
 
1783
- // [re.results.const], construct/copy/destroy:
1784
  explicit match_results(const Allocator& a = Allocator());
1785
  match_results(const match_results& m);
1786
  match_results(match_results&& m) noexcept;
1787
  match_results& operator=(const match_results& m);
1788
  match_results& operator=(match_results&& m);
1789
  ~match_results();
1790
 
1791
- // [re.results.state], state:
1792
  bool ready() const;
1793
 
1794
- // [re.results.size], size:
1795
  size_type size() const;
1796
  size_type max_size() const;
1797
  bool empty() const;
1798
 
1799
- // [re.results.acc], element access:
1800
  difference_type length(size_type sub = 0) const;
1801
  difference_type position(size_type sub = 0) const;
1802
  string_type str(size_type sub = 0) const;
1803
  const_reference operator[](size_type n) const;
1804
 
@@ -1807,37 +1803,33 @@ namespace std {
1807
  const_iterator begin() const;
1808
  const_iterator end() const;
1809
  const_iterator cbegin() const;
1810
  const_iterator cend() const;
1811
 
1812
- // [re.results.form], format:
1813
  template <class OutputIter>
1814
  OutputIter
1815
  format(OutputIter out,
1816
  const char_type* fmt_first, const char_type* fmt_last,
1817
- regex_constants::match_flag_type flags =
1818
- regex_constants::format_default) const;
1819
  template <class OutputIter, class ST, class SA>
1820
  OutputIter
1821
  format(OutputIter out,
1822
  const basic_string<char_type, ST, SA>& fmt,
1823
- regex_constants::match_flag_type flags =
1824
- regex_constants::format_default) const;
1825
  template <class ST, class SA>
1826
  basic_string<char_type, ST, SA>
1827
  format(const basic_string<char_type, ST, SA>& fmt,
1828
- regex_constants::match_flag_type flags =
1829
- regex_constants::format_default) const;
1830
  string_type
1831
  format(const char_type* fmt,
1832
- regex_constants::match_flag_type flags =
1833
- regex_constants::format_default) const;
1834
 
1835
- // [re.results.all], allocator:
1836
  allocator_type get_allocator() const;
1837
 
1838
- // [re.results.swap], swap:
1839
  void swap(match_results& that);
1840
  };
1841
  }
1842
  ```
1843
 
@@ -1864,11 +1856,11 @@ match_results(const match_results& m);
1864
 
1865
  ``` cpp
1866
  match_results(match_results&& m) noexcept;
1867
  ```
1868
 
1869
- *Effects:*  Move-constructs an object of class `match_results` from `m`
1870
  satisfying the same postconditions as Table  [[tab:re:results:assign]].
1871
  Additionally, the stored `Allocator` value is move constructed from
1872
  `m.get_allocator()`.
1873
 
1874
  *Throws:* Nothing.
@@ -1916,15 +1908,16 @@ otherwise `false`.
1916
  size_type size() const;
1917
  ```
1918
 
1919
  *Returns:* One plus the number of marked sub-expressions in the regular
1920
  expression that was matched if `*this` represents the result of a
1921
- successful match. Otherwise returns `0`. The state of a `match_results`
1922
- object can be modified only by passing that object to `regex_match` or
1923
- `regex_search`. Sections  [[re.alg.match]] and  [[re.alg.search]]
1924
- specify the effects of those algorithms on their `match_results`
1925
- arguments.
 
1926
 
1927
  ``` cpp
1928
  size_type max_size() const;
1929
  ```
1930
 
@@ -2015,69 +2008,76 @@ sub-expressions stored in `*this`.
2015
 
2016
  ### `match_results` formatting <a id="re.results.form">[[re.results.form]]</a>
2017
 
2018
  ``` cpp
2019
  template <class OutputIter>
2020
- OutputIter format(OutputIter out,
 
2021
  const char_type* fmt_first, const char_type* fmt_last,
2022
- regex_constants::match_flag_type flags =
2023
- regex_constants::format_default) const;
2024
  ```
2025
 
2026
- *Requires:*  ready() == true and `OutputIter` shall satisfy the
2027
  requirements for an Output Iterator ([[output.iterators]]).
2028
 
2029
  *Effects:* Copies the character sequence \[`fmt_first`, `fmt_last`) to
2030
  OutputIter `out`. Replaces each format specifier or escape sequence in
2031
  the copied range with either the character(s) it represents or the
2032
  sequence of characters within `*this` to which it refers. The bitmasks
2033
  specified in `flags` determine which format specifiers and escape
2034
  sequences are recognized.
2035
 
2036
- *Returns:*  `out`.
2037
 
2038
  ``` cpp
2039
  template <class OutputIter, class ST, class SA>
2040
- OutputIter format(OutputIter out,
 
2041
  const basic_string<char_type, ST, SA>& fmt,
2042
- regex_constants::match_flag_type flags =
2043
- regex_constants::format_default) const;
2044
  ```
2045
 
2046
- *Effects:* Equivalent to `return format(out, fmt.data(),`
2047
- `fmt.data() + fmt.size(), flags)`.
 
 
 
2048
 
2049
  ``` cpp
2050
  template <class ST, class SA>
2051
- basic_string<char_type, ST, SA>
2052
- format(const basic_string<char_type, ST, SA>& fmt,
2053
- regex_constants::match_flag_type flags =
2054
- regex_constants::format_default) const;
2055
  ```
2056
 
2057
  *Requires:* `ready() == true`.
2058
 
2059
  *Effects:* Constructs an empty string `result` of type
2060
- `basic_string<char_type, ST, SA>` and calls
2061
- `format(back_inserter(result), fmt, flags)`.
2062
 
2063
- *Returns:*  `result`.
 
 
 
 
2064
 
2065
  ``` cpp
2066
- string_type
2067
- format(const char_type* fmt,
2068
- regex_constants::match_flag_type flags =
2069
- regex_constants::format_default) const;
2070
  ```
2071
 
2072
  *Requires:* `ready() == true`.
2073
 
2074
- *Effects:*  Constructs an empty string `result` of type `string_type`
2075
- and
2076
- calls`format(back_inserter(result), fmt, fmt + char_traits<char_type>::length(fmt), flags)`.
2077
 
2078
- *Returns:*  `result`.
 
 
 
 
2079
 
2080
  ### `match_results` allocator <a id="re.results.all">[[re.results.all]]</a>
2081
 
2082
  ``` cpp
2083
  allocator_type get_allocator() const;
@@ -2093,23 +2093,23 @@ recent replacement.
2093
  void swap(match_results& that);
2094
  ```
2095
 
2096
  *Effects:* Swaps the contents of the two sequences.
2097
 
2098
- `*this` contains the sequence of matched sub-expressions that were in
2099
- `that`, `that` contains the sequence of matched sub-expressions that
2100
- were in `*this`.
2101
 
2102
  *Complexity:* Constant time.
2103
 
2104
  ``` cpp
2105
  template <class BidirectionalIterator, class Allocator>
2106
  void swap(match_results<BidirectionalIterator, Allocator>& m1,
2107
  match_results<BidirectionalIterator, Allocator>& m2);
2108
  ```
2109
 
2110
- *Effects:* `m1.swap(m2)`.
2111
 
2112
  ### `match_results` non-member functions <a id="re.results.nonmember">[[re.results.nonmember]]</a>
2113
 
2114
  ``` cpp
2115
  template <class BidirectionalIterator, class Allocator>
@@ -2127,11 +2127,12 @@ returns `true` only if:
2127
  - `m1.prefix() == m2.prefix()`,
2128
  - `m1.size() == m2.size() && equal(m1.begin(), m1.end(), m2.begin())`,
2129
  and
2130
  - `m1.suffix() == m2.suffix()`.
2131
 
2132
- The algorithm `equal` is defined in Clause  [[algorithms]].
 
2133
 
2134
  ``` cpp
2135
  template <class BidirectionalIterator, class Allocator>
2136
  bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
2137
  const match_results<BidirectionalIterator, Allocator>& m2);
@@ -2139,11 +2140,11 @@ bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
2139
 
2140
  *Returns:* `!(m1 == m2)`.
2141
 
2142
  ## Regular expression algorithms <a id="re.alg">[[re.alg]]</a>
2143
 
2144
- ### exceptions <a id="re.except">[[re.except]]</a>
2145
 
2146
  The algorithms described in this subclause may throw an exception of
2147
  type `regex_error`. If such an exception `e` is thrown, `e.code()` shall
2148
  return either `regex_constants::error_complexity` or
2149
  `regex_constants::error_stack`.
@@ -2153,23 +2154,35 @@ return either `regex_constants::error_complexity` or
2153
  ``` cpp
2154
  template <class BidirectionalIterator, class Allocator, class charT, class traits>
2155
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
2156
  match_results<BidirectionalIterator, Allocator>& m,
2157
  const basic_regex<charT, traits>& e,
2158
- regex_constants::match_flag_type flags =
2159
- regex_constants::match_default);
2160
  ```
2161
 
2162
  *Requires:* The type `BidirectionalIterator` shall satisfy the
2163
- requirements of a Bidirectional Iterator
2164
-  ([[bidirectional.iterators]]).
2165
 
2166
  *Effects:* Determines whether there is a match between the regular
2167
  expression `e`, and all of the character sequence \[`first`, `last`).
2168
  The parameter `flags` is used to control how the expression is matched
2169
- against the character sequence. Returns `true` if such a match exists,
2170
- `false` otherwise.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2171
 
2172
  *Postconditions:* `m.ready() == true` in all cases. If the function
2173
  returns `false`, then the effect on parameter `m` is unspecified except
2174
  that `m.size()` returns `0` and `m.empty()` returns `true`. Otherwise
2175
  the effects on parameter `m` are given in Table  [[tab:re:alg:match]].
@@ -2177,30 +2190,29 @@ the effects on parameter `m` are given in Table  [[tab:re:alg:match]].
2177
  **Table: Effects of `regex_match` algorithm** <a id="tab:re:alg:match">[tab:re:alg:match]</a>
2178
 
2179
  | Element | Value |
2180
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2181
  | `m.size()` | `1 + e.mark_count()` |
2182
- | `m.empty()` | false |
2183
- | `m.prefix().first` | first |
2184
- | `m.prefix().second` | first |
2185
- | `m.prefix().matched` | false |
2186
- | `m.suffix().first` | last |
2187
- | `m.suffix().second` | last |
2188
- | `m.suffix().matched` | false |
2189
- | `m[0].first` | first |
2190
- | `m[0].second` | last |
2191
  | `m[0].matched` | `true` |
2192
  | `m[n].first` | For all integers `0 < n < m.size()`, the start of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
2193
  | `m[n].second` | For all integers `0 < n < m.size()`, the end of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
2194
  | `m[n].matched` | For all integers `0 < n < m.size()`, `true` if sub-expression `n` participated in the match, `false` otherwise. |
2195
 
2196
  ``` cpp
2197
  template <class BidirectionalIterator, class charT, class traits>
2198
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
2199
  const basic_regex<charT, traits>& e,
2200
- regex_constants::match_flag_type flags =
2201
- regex_constants::match_default);
2202
  ```
2203
 
2204
  *Effects:* Behaves “as if” by constructing an instance of
2205
  `match_results<BidirectionalIterator> what`, and then returning the
2206
  result of `regex_match(first, last, what, e, flags)`.
@@ -2208,47 +2220,42 @@ result of `regex_match(first, last, what, e, flags)`.
2208
  ``` cpp
2209
  template <class charT, class Allocator, class traits>
2210
  bool regex_match(const charT* str,
2211
  match_results<const charT*, Allocator>& m,
2212
  const basic_regex<charT, traits>& e,
2213
- regex_constants::match_flag_type flags =
2214
- regex_constants::match_default);
2215
  ```
2216
 
2217
  *Returns:*
2218
  `regex_match(str, str + char_traits<charT>::length(str), m, e, flags)`.
2219
 
2220
  ``` cpp
2221
  template <class ST, class SA, class Allocator, class charT, class traits>
2222
  bool regex_match(const basic_string<charT, ST, SA>& s,
2223
- match_results<
2224
- typename basic_string<charT, ST, SA>::const_iterator,
2225
  Allocator>& m,
2226
  const basic_regex<charT, traits>& e,
2227
- regex_constants::match_flag_type flags =
2228
- regex_constants::match_default);
2229
  ```
2230
 
2231
  *Returns:* `regex_match(s.begin(), s.end(), m, e, flags)`.
2232
 
2233
  ``` cpp
2234
  template <class charT, class traits>
2235
  bool regex_match(const charT* str,
2236
  const basic_regex<charT, traits>& e,
2237
- regex_constants::match_flag_type flags =
2238
- regex_constants::match_default);
2239
  ```
2240
 
2241
  *Returns:*
2242
  `regex_match(str, str + char_traits<charT>::length(str), e, flags)`
2243
 
2244
  ``` cpp
2245
  template <class ST, class SA, class charT, class traits>
2246
  bool regex_match(const basic_string<charT, ST, SA>& s,
2247
  const basic_regex<charT, traits>& e,
2248
- regex_constants::match_flag_type flags =
2249
- regex_constants::match_default);
2250
  ```
2251
 
2252
  *Returns:* `regex_match(s.begin(), s.end(), e, flags)`.
2253
 
2254
  ### `regex_search` <a id="re.alg.search">[[re.alg.search]]</a>
@@ -2256,12 +2263,11 @@ template <class ST, class SA, class charT, class traits>
2256
  ``` cpp
2257
  template <class BidirectionalIterator, class Allocator, class charT, class traits>
2258
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
2259
  match_results<BidirectionalIterator, Allocator>& m,
2260
  const basic_regex<charT, traits>& e,
2261
- regex_constants::match_flag_type flags =
2262
- regex_constants::match_default);
2263
  ```
2264
 
2265
  *Requires:* Type `BidirectionalIterator` shall satisfy the requirements
2266
  of a Bidirectional Iterator ([[bidirectional.iterators]]).
2267
 
@@ -2297,60 +2303,53 @@ the effects on parameter `m` are given in Table  [[tab:re:alg:search]].
2297
 
2298
  ``` cpp
2299
  template <class charT, class Allocator, class traits>
2300
  bool regex_search(const charT* str, match_results<const charT*, Allocator>& m,
2301
  const basic_regex<charT, traits>& e,
2302
- regex_constants::match_flag_type flags =
2303
- regex_constants::match_default);
2304
  ```
2305
 
2306
- *Returns:* The result of
2307
  `regex_search(str, str + char_traits<charT>::length(str), m, e, flags)`.
2308
 
2309
  ``` cpp
2310
  template <class ST, class SA, class Allocator, class charT, class traits>
2311
  bool regex_search(const basic_string<charT, ST, SA>& s,
2312
- match_results<
2313
- typename basic_string<charT, ST, SA>::const_iterator,
2314
  Allocator>& m,
2315
  const basic_regex<charT, traits>& e,
2316
- regex_constants::match_flag_type flags =
2317
- regex_constants::match_default);
2318
  ```
2319
 
2320
- *Returns:* The result of
2321
- `regex_search(s.begin(), s.end(), m, e, flags)`.
2322
 
2323
  ``` cpp
2324
  template <class BidirectionalIterator, class charT, class traits>
2325
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
2326
  const basic_regex<charT, traits>& e,
2327
- regex_constants::match_flag_type flags =
2328
- regex_constants::match_default);
2329
  ```
2330
 
2331
  *Effects:* Behaves “as if” by constructing an object `what` of type
2332
- `match_results<BidirectionalIterator>` and then returning the result of
2333
  `regex_search(first, last, what, e, flags)`.
2334
 
2335
  ``` cpp
2336
  template <class charT, class traits>
2337
  bool regex_search(const charT* str,
2338
  const basic_regex<charT, traits>& e,
2339
- regex_constants::match_flag_type flags =
2340
- regex_constants::match_default);
2341
  ```
2342
 
2343
  *Returns:*
2344
- `regex_search(str, str + char_traits<charT>::length(str), e, flags)`
2345
 
2346
  ``` cpp
2347
  template <class ST, class SA, class charT, class traits>
2348
  bool regex_search(const basic_string<charT, ST, SA>& s,
2349
  const basic_regex<charT, traits>& e,
2350
- regex_constants::match_flag_type flags =
2351
- regex_constants::match_default);
2352
  ```
2353
 
2354
  *Returns:* `regex_search(s.begin(), s.end(), e, flags)`.
2355
 
2356
  ### `regex_replace` <a id="re.alg.replace">[[re.alg.replace]]</a>
@@ -2361,21 +2360,18 @@ template <class OutputIterator, class BidirectionalIterator,
2361
  OutputIterator
2362
  regex_replace(OutputIterator out,
2363
  BidirectionalIterator first, BidirectionalIterator last,
2364
  const basic_regex<charT, traits>& e,
2365
  const basic_string<charT, ST, SA>& fmt,
2366
- regex_constants::match_flag_type flags =
2367
- regex_constants::match_default);
2368
- template <class OutputIterator, class BidirectionalIterator,
2369
- class traits, class charT>
2370
  OutputIterator
2371
  regex_replace(OutputIterator out,
2372
  BidirectionalIterator first, BidirectionalIterator last,
2373
  const basic_regex<charT, traits>& e,
2374
  const charT* fmt,
2375
- regex_constants::match_flag_type flags =
2376
- regex_constants::match_default);
2377
  ```
2378
 
2379
  *Effects:* Constructs a `regex_iterator` object `i` as if by
2380
 
2381
  ``` cpp
@@ -2383,21 +2379,21 @@ regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags)
2383
  ```
2384
 
2385
  and uses `i` to enumerate through all of the matches `m` of type
2386
  `match_results<BidirectionalIterator>` that occur within the sequence
2387
  \[`first`, `last`). If no such matches are found and
2388
- `!(flags & regex_constants::format_no_copy)` then calls
2389
 
2390
  ``` cpp
2391
- out = std::copy(first, last, out)
2392
  ```
2393
 
2394
  If any matches are found then, for each such match:
2395
 
2396
  - If `!(flags & regex_constants::format_no_copy)`, calls
2397
  ``` cpp
2398
- out = std::copy(m.prefix().first, m.prefix().second, out)
2399
  ```
2400
  - Then calls
2401
  ``` cpp
2402
  out = m.format(out, fmt, flags)
2403
  ```
@@ -2411,64 +2407,66 @@ If any matches are found then, for each such match:
2411
 
2412
  Finally, if such a match is found and
2413
  `!(flags & regex_constants::format_no_copy)`, calls
2414
 
2415
  ``` cpp
2416
- out = std::copy(last_m.suffix().first, last_m.suffix().second, out)
2417
  ```
2418
 
2419
  where `last_m` is a copy of the last match found. If
2420
- `flags & regex_constants::format_first_only` is non-zero then only the
2421
  first match found is replaced.
2422
 
2423
  *Returns:* `out`.
2424
 
2425
  ``` cpp
2426
  template <class traits, class charT, class ST, class SA, class FST, class FSA>
2427
  basic_string<charT, ST, SA>
2428
  regex_replace(const basic_string<charT, ST, SA>& s,
2429
  const basic_regex<charT, traits>& e,
2430
  const basic_string<charT, FST, FSA>& fmt,
2431
- regex_constants::match_flag_type flags =
2432
- regex_constants::match_default);
2433
  template <class traits, class charT, class ST, class SA>
2434
  basic_string<charT, ST, SA>
2435
  regex_replace(const basic_string<charT, ST, SA>& s,
2436
  const basic_regex<charT, traits>& e,
2437
  const charT* fmt,
2438
- regex_constants::match_flag_type flags =
2439
- regex_constants::match_default);
2440
  ```
2441
 
2442
  *Effects:* Constructs an empty string `result` of type
2443
- `basic_string<charT, ST, SA>` and calls
2444
- `regex_replace(back_inserter(result), s.begin(), s.end(), e, fmt, flags)`.
2445
 
2446
- *Returns:*  `result`.
 
 
 
 
2447
 
2448
  ``` cpp
2449
  template <class traits, class charT, class ST, class SA>
2450
  basic_string<charT>
2451
  regex_replace(const charT* s,
2452
  const basic_regex<charT, traits>& e,
2453
  const basic_string<charT, ST, SA>& fmt,
2454
- regex_constants::match_flag_type flags =
2455
- regex_constants::match_default);
2456
  template <class traits, class charT>
2457
  basic_string<charT>
2458
  regex_replace(const charT* s,
2459
  const basic_regex<charT, traits>& e,
2460
  const charT* fmt,
2461
- regex_constants::match_flag_type flags =
2462
- regex_constants::match_default);
2463
  ```
2464
 
2465
  *Effects:* Constructs an empty string `result` of type
2466
- `basic_string<charT>` and calls `regex_replace(`
2467
- `back_inserter(result), s, s + char_traits<charT>::length(s), e, fmt, flags)`.
2468
 
2469
- *Returns:*  `result`.
 
 
 
 
2470
 
2471
  ## Regular expression iterators <a id="re.iter">[[re.iter]]</a>
2472
 
2473
  ### Class template `regex_iterator` <a id="re.regiter">[[re.regiter]]</a>
2474
 
@@ -2494,39 +2492,37 @@ is not equal to a non-end-of-sequence iterator. Two non-end-of-sequence
2494
  iterators are equal when they are constructed from the same arguments.
2495
 
2496
  ``` cpp
2497
  namespace std {
2498
  template <class BidirectionalIterator,
2499
- class charT = typename iterator_traits<
2500
- BidirectionalIterator>::value_type,
2501
  class traits = regex_traits<charT>>
2502
  class regex_iterator {
2503
  public:
2504
- typedef basic_regex<charT, traits> regex_type;
2505
- typedef match_results<BidirectionalIterator> value_type;
2506
- typedef std::ptrdiff_t difference_type;
2507
- typedef const value_type* pointer;
2508
- typedef const value_type& reference;
2509
- typedef std::forward_iterator_tag iterator_category;
2510
 
2511
  regex_iterator();
2512
  regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
2513
  const regex_type& re,
2514
- regex_constants::match_flag_type m =
2515
- regex_constants::match_default);
2516
- regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
2517
- const regex_type&& re,
2518
- regex_constants::match_flag_type m =
2519
- regex_constants::match_default) = delete;
2520
  regex_iterator(const regex_iterator&);
2521
  regex_iterator& operator=(const regex_iterator&);
2522
  bool operator==(const regex_iterator&) const;
2523
  bool operator!=(const regex_iterator&) const;
2524
  const value_type& operator*() const;
2525
  const value_type* operator->() const;
2526
  regex_iterator& operator++();
2527
  regex_iterator operator++(int);
 
2528
  private:
2529
  BidirectionalIterator begin; // exposition only
2530
  BidirectionalIterator end; // exposition only
2531
  const regex_type* pregex; // exposition only
2532
  regex_constants::match_flag_type flags; // exposition only
@@ -2535,13 +2531,15 @@ namespace std {
2535
  }
2536
  ```
2537
 
2538
  An object of type `regex_iterator` that is not an end-of-sequence
2539
  iterator holds a *zero-length match* if `match[0].matched == true` and
2540
- `match[0].first == match[0].second`. For example, this can occur when
2541
- the part of the regular expression that matched consists only of an
2542
- assertion (such as `'^'`, `'$'`, `'\b'`, `'\B'`).
 
 
2543
 
2544
  #### `regex_iterator` constructors <a id="re.regiter.cnstr">[[re.regiter.cnstr]]</a>
2545
 
2546
  ``` cpp
2547
  regex_iterator();
@@ -2609,43 +2607,50 @@ regex_iterator& operator++();
2609
 
2610
  If the iterator holds a zero-length match and `start == end` the
2611
  operator sets `*this` to the end-of-sequence iterator and returns
2612
  `*this`.
2613
 
2614
- Otherwise, if the iterator holds a zero-length match the operator calls
2615
- `regex_search(start, end, match, *pregex, flags `|` regex_constants::match_not_null `|` regex_constants::match_`
2616
- `continuous)`. If the call returns `true` the operator returns `*this`.
2617
- Otherwise the operator increments `start` and continues as if the most
2618
- recent match was not a zero-length match.
 
 
 
 
 
 
2619
 
2620
  If the most recent match was not a zero-length match, the operator sets
2621
- `flags` to `flags `|` regex_constants ``match_prev_avail` and calls
2622
  `regex_search(start, end, match, *pregex, flags)`. If the call returns
2623
  `false` the iterator sets `*this` to the end-of-sequence iterator. The
2624
  iterator then returns `*this`.
2625
 
2626
  In all cases in which the call to `regex_search` returns `true`,
2627
  `match.prefix().first` shall be equal to the previous value of
2628
  `match[0].second`, and for each index `i` in the half-open range
2629
- `[0, match.size())` for which `match[i].matched` is true,
2630
- `match[i].position()` shall return `distance(begin, match[i].first)`.
2631
 
2632
- This means that `match[i].position()` gives the offset from the
2633
- beginning of the target sequence, which is often not the same as the
2634
- offset from the sequence passed in the call to `regex_search`.
 
2635
 
2636
  It is unspecified how the implementation makes these adjustments.
2637
 
2638
- This means that a compiler may call an implementation-specific search
2639
- function, in which case a user-defined specialization of `regex_search`
2640
- will not be called.
2641
 
2642
  ``` cpp
2643
  regex_iterator operator++(int);
2644
  ```
2645
 
2646
- *Effects:*
2647
 
2648
  ``` cpp
2649
  regex_iterator tmp = *this;
2650
  ++(*this);
2651
  return tmp;
@@ -2697,39 +2702,38 @@ is not equal to a non-end-of-sequence iterator. Two non-end-of-sequence
2697
  iterators are equal when they are constructed from the same arguments.
2698
 
2699
  ``` cpp
2700
  namespace std {
2701
  template <class BidirectionalIterator,
2702
- class charT = typename iterator_traits<
2703
- BidirectionalIterator>::value_type,
2704
  class traits = regex_traits<charT>>
2705
  class regex_token_iterator {
2706
  public:
2707
- typedef basic_regex<charT, traits> regex_type;
2708
- typedef sub_match<BidirectionalIterator> value_type;
2709
- typedef std::ptrdiff_t difference_type;
2710
- typedef const value_type* pointer;
2711
- typedef const value_type& reference;
2712
- typedef std::forward_iterator_tag iterator_category;
2713
 
2714
  regex_token_iterator();
2715
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2716
  const regex_type& re,
2717
  int submatch = 0,
2718
  regex_constants::match_flag_type m =
2719
  regex_constants::match_default);
2720
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2721
  const regex_type& re,
2722
- const std::vector<int>& submatches,
2723
  regex_constants::match_flag_type m =
2724
  regex_constants::match_default);
2725
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2726
  const regex_type& re,
2727
  initializer_list<int> submatches,
2728
  regex_constants::match_flag_type m =
2729
  regex_constants::match_default);
2730
- template <std::size_t N>
2731
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2732
  const regex_type& re,
2733
  const int (&submatches)[N],
2734
  regex_constants::match_flag_type m =
2735
  regex_constants::match_default);
@@ -2738,19 +2742,19 @@ namespace std {
2738
  int submatch = 0,
2739
  regex_constants::match_flag_type m =
2740
  regex_constants::match_default) = delete;
2741
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2742
  const regex_type&& re,
2743
- const std::vector<int>& submatches,
2744
  regex_constants::match_flag_type m =
2745
  regex_constants::match_default) = delete;
2746
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2747
  const regex_type&& re,
2748
  initializer_list<int> submatches,
2749
  regex_constants::match_flag_type m =
2750
  regex_constants::match_default) = delete;
2751
- template <std::size_t N>
2752
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2753
  const regex_type&& re,
2754
  const int (&submatches)[N],
2755
  regex_constants::match_flag_type m =
2756
  regex_constants::match_default) = delete;
@@ -2760,18 +2764,19 @@ namespace std {
2760
  bool operator!=(const regex_token_iterator&) const;
2761
  const value_type& operator*() const;
2762
  const value_type* operator->() const;
2763
  regex_token_iterator& operator++();
2764
  regex_token_iterator operator++(int);
 
2765
  private:
2766
- typedef
2767
- regex_iterator<BidirectionalIterator, charT, traits> position_iterator; // exposition only
2768
  position_iterator position; // exposition only
2769
  const value_type* result; // exposition only
2770
  value_type suffix; // exposition only
2771
- std::size_t N; // exposition only
2772
- std::vector<int> subs; // exposition only
2773
  };
2774
  }
2775
  ```
2776
 
2777
  A *suffix iterator* is a `regex_token_iterator` object that points to a
@@ -2779,13 +2784,13 @@ final sequence of characters at the end of the target sequence. In a
2779
  suffix iterator the member `result` holds a pointer to the data member
2780
  `suffix`, the value of the member `suffix.match` is `true`,
2781
  `suffix.first` points to the beginning of the final sequence, and
2782
  `suffix.second` points to the end of the final sequence.
2783
 
2784
- For a suffix iterator, data member `suffix.first` is the same as the end
2785
- of the last match found, and `suffix.second` is the same as the end of
2786
- the target sequence
2787
 
2788
  The *current match* is `(*position).prefix()` if `subs[N] == -1`, or
2789
  `(*position)[subs[N]]` for any other value of `subs[N]`.
2790
 
2791
  #### `regex_token_iterator` constructors <a id="re.tokiter.cnstr">[[re.tokiter.cnstr]]</a>
@@ -2798,31 +2803,27 @@ regex_token_iterator();
2798
 
2799
  ``` cpp
2800
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2801
  const regex_type& re,
2802
  int submatch = 0,
2803
- regex_constants::match_flag_type m =
2804
- regex_constants::match_default);
2805
 
2806
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2807
  const regex_type& re,
2808
- const std::vector<int>& submatches,
2809
- regex_constants::match_flag_type m =
2810
- regex_constants::match_default);
2811
 
2812
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2813
  const regex_type& re,
2814
  initializer_list<int> submatches,
2815
- regex_constants::match_flag_type m =
2816
- regex_constants::match_default);
2817
 
2818
- template <std::size_t N>
2819
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2820
  const regex_type& re,
2821
  const int (&submatches)[N],
2822
- regex_constants::match_flag_type m =
2823
- regex_constants::match_default);
2824
  ```
2825
 
2826
  *Requires:* Each of the initialization values of `submatches` shall be
2827
  `>= -1`.
2828
 
@@ -2933,10 +2934,13 @@ ClassAtom ::
2933
  -
2934
  ClassAtomNoDash
2935
  ClassAtomExClass
2936
  ClassAtomCollatingElement
2937
  ClassAtomEquivalence
 
 
 
2938
  ```
2939
 
2940
  The following new productions are then added:
2941
 
2942
  ``` cpp
@@ -3005,40 +3009,42 @@ When the sequence of characters being transformed to a finite state
3005
  machine contains an invalid class name the translator shall throw an
3006
  exception object of type `regex_error`.
3007
 
3008
  If the *CV* of a *UnicodeEscapeSequence* is greater than the largest
3009
  value that can be held in an object of type `charT` the translator shall
3010
- throw an exception object of type `regex_error`. This means that values
3011
- of the form `"uxxxx"` that do not fit in a character are invalid.
 
 
3012
 
3013
  Where the regular expression grammar requires the conversion of a
3014
  sequence of characters to an integral value, this is accomplished by
3015
  calling `traits_inst.value`.
3016
 
3017
  The behavior of the internal finite state machine representation when
3018
  used to match a sequence of characters is as described in ECMA-262. The
3019
- behavior is modified according to any match_flag_type flags 
3020
- [[re.matchflag]] specified when using the regular expression object in
3021
- one of the regular expression algorithms  [[re.alg]]. The behavior is
3022
  also localized by interaction with the traits class template parameter
3023
  as follows:
3024
 
3025
  - During matching of a regular expression finite state machine against a
3026
  sequence of characters, two characters `c` and `d` are compared using
3027
  the following rules:
3028
- 1. if `(flags() & regex_constants::icase)` the two characters are
3029
- equal if
3030
  `traits_inst.translate_nocase(c) == traits_inst.translate_nocase(d)`;
3031
- 2. otherwise, if `flags() & regex_constants::collate` the two
3032
  characters are equal if
3033
  `traits_inst.translate(c) == traits_inst.translate(d)`;
3034
- 3. otherwise, the two characters are equal if `c == d`.
3035
  - During matching of a regular expression finite state machine against a
3036
  sequence of characters, comparison of a collating element range
3037
  `c1-c2` against a character `c` is conducted as follows: if
3038
- `flags() & regex_constants \colcol
3039
- collate` is false then the character `c` is matched if `c1
3040
  <= c && c <= c2`, otherwise `c` is matched in accordance with the
3041
  following algorithm:
3042
  ``` cpp
3043
  string_type str1 = string_type(1,
3044
  flags() & icase ?
@@ -3068,10 +3074,11 @@ as follows:
3068
 
3069
  <!-- Link reference definitions -->
3070
  [algorithms]: algorithms.md#algorithms
3071
  [bidirectional.iterators]: iterators.md#bidirectional.iterators
3072
  [bitmask.types]: library.md#bitmask.types
 
3073
  [enumerated.types]: library.md#enumerated.types
3074
  [forward.iterators]: iterators.md#forward.iterators
3075
  [input.iterators]: iterators.md#input.iterators
3076
  [output.iterators]: iterators.md#output.iterators
3077
  [re]: #re
@@ -3122,17 +3129,18 @@ as follows:
3122
  [re.tokiter.comp]: #re.tokiter.comp
3123
  [re.tokiter.deref]: #re.tokiter.deref
3124
  [re.tokiter.incr]: #re.tokiter.incr
3125
  [re.traits]: #re.traits
3126
  [sequence.reqmts]: containers.md#sequence.reqmts
 
3127
  [tab:re.lib.summary]: #tab:re.lib.summary
3128
  [tab:re.traits.classnames]: #tab:re.traits.classnames
3129
  [tab:re:RegexpTraits]: #tab:re:RegexpTraits
3130
  [tab:re:alg:match]: #tab:re:alg:match
3131
  [tab:re:alg:search]: #tab:re:alg:search
3132
  [tab:re:errortype]: #tab:re:errortype
3133
  [tab:re:matchflag]: #tab:re:matchflag
3134
  [tab:re:results:assign]: #tab:re:results:assign
3135
  [tab:re:syntaxoption]: #tab:re:syntaxoption
3136
 
3137
- [^1]: For example, if the parameter `icase` is true then `[[:lower:]]`
3138
  is the same as `[[:alpha:]]`.
 
4
 
5
  This Clause describes components that C++programs may use to perform
6
  operations involving regular expression matching and searching.
7
 
8
  The following subclauses describe a basic regular expression class
9
+ template and its traits that can handle char-like ([[strings.general]])
10
+ template arguments, two specializations of this class template that
11
+ handle sequences of `char` and `wchar_t`, a class template that holds
12
+ the result of a regular expression match, a series of algorithms that
13
+ allow a character sequence to be operated upon by a regular expression,
14
+ and two iterator types for enumerating regular expression matches, as
15
+ described in Table  [[tab:re.lib.summary]].
16
 
17
  **Table: Regular expressions library summary** <a id="tab:re.lib.summary">[tab:re.lib.summary]</a>
18
 
19
  | Subclause | | Header |
20
  | --------------- | --------------------------- | --------- |
 
72
  a subset of a regular expression that has been marked by parenthesis.
73
 
74
  ## Requirements <a id="re.req">[[re.req]]</a>
75
 
76
  This subclause defines requirements on classes representing regular
77
+ expression traits.
78
+
79
+ [*Note 1*: The class template `regex_traits`, defined in Clause 
80
+ [[re.traits]], satisfies these requirements. — *end note*]
81
 
82
  The class template `basic_regex`, defined in Clause  [[re.regex]], needs
83
  a set of related types and functions to complete the definition of its
84
  semantics. These types and functions are provided as a set of member
85
+ *typedef-name*s and functions in the template parameter `traits` used by
86
+ the `basic_regex` class template. This subclause defines the semantics
87
+ of these members.
88
 
89
  To specialize class template `basic_regex` for a character container
90
  `CharT` and its related regular expression traits class `Traits`, use
91
  `basic_regex<CharT, Traits>`.
92
 
 
99
  object of type `X::string_type`; `cs` is an object of type
100
  `const X::string_type`; `b` is a value of type `bool`; `I` is a value of
101
  type `int`; `cl` is an object of type `X::char_class_type`, and `loc` is
102
  an object of type `X::locale_type`.
103
 
104
+ [*Note 2*: The value of *I* will only be 8, 10, or 16. — *end note*]
105
+
106
+ [*Note 3*: Class template `regex_traits` satisfies the requirements for
107
+ a regular expression traits class when it is specialized for `char` or
108
+ `wchar_t`. This class template is described in the header `<regex>`, and
109
+ is described in Clause  [[re.traits]]. — *end note*]
110
 
111
  ## Header `<regex>` synopsis <a id="re.syn">[[re.syn]]</a>
112
 
113
  ``` cpp
114
  #include <initializer_list>
115
 
116
  namespace std {
117
+ // [re.const], regex constants
 
118
  namespace regex_constants {
119
+ using syntax_option_type = T1;
120
+ using match_flag_type = T2;
121
+ using error_type = T3;
122
+ }
123
 
124
+ // [re.badexp], class regex_error
125
  class regex_error;
126
 
127
+ // [re.traits], class template regex_traits
128
  template <class charT> struct regex_traits;
129
 
130
+ // [re.regex], class template basic_regex
131
  template <class charT, class traits = regex_traits<charT>> class basic_regex;
132
 
133
+ using regex = basic_regex<char>;
134
+ using wregex = basic_regex<wchar_t>;
135
 
136
+ // [re.regex.swap], basic_regex swap
137
  template <class charT, class traits>
138
  void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
139
 
140
+ // [re.submatch], class template sub_match
141
  template <class BidirectionalIterator>
142
  class sub_match;
143
 
144
+ using csub_match = sub_match<const char*>;
145
+ using wcsub_match = sub_match<const wchar_t*>;
146
+ using ssub_match = sub_match<string::const_iterator>;
147
+ using wssub_match = sub_match<wstring::const_iterator>;
148
 
149
+ // [re.submatch.op], sub_match non-member operators
150
  template <class BiIter>
151
  bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
152
  template <class BiIter>
153
  bool operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
154
  template <class BiIter>
 
158
  template <class BiIter>
159
  bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
160
  template <class BiIter>
161
  bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
162
 
 
163
  template <class BiIter, class ST, class SA>
164
  bool operator==(
165
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
166
  const sub_match<BiIter>& rhs);
167
  template <class BiIter, class ST, class SA>
168
  bool operator!=(
169
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
170
  const sub_match<BiIter>& rhs);
171
  template <class BiIter, class ST, class SA>
172
  bool operator<(
173
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
174
  const sub_match<BiIter>& rhs);
175
  template <class BiIter, class ST, class SA>
176
  bool operator>(
177
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
178
  const sub_match<BiIter>& rhs);
179
  template <class BiIter, class ST, class SA>
180
  bool operator>=(
181
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
182
  const sub_match<BiIter>& rhs);
183
  template <class BiIter, class ST, class SA>
184
  bool operator<=(
185
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
186
  const sub_match<BiIter>& rhs);
187
 
188
  template <class BiIter, class ST, class SA>
189
  bool operator==(
190
  const sub_match<BiIter>& lhs,
191
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
192
  template <class BiIter, class ST, class SA>
193
  bool operator!=(
194
  const sub_match<BiIter>& lhs,
195
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
196
  template <class BiIter, class ST, class SA>
197
  bool operator<(
198
  const sub_match<BiIter>& lhs,
199
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
200
  template <class BiIter, class ST, class SA>
201
  bool operator>(
202
  const sub_match<BiIter>& lhs,
203
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
204
  template <class BiIter, class ST, class SA>
205
  bool operator>=(
206
  const sub_match<BiIter>& lhs,
207
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
208
  template <class BiIter, class ST, class SA>
209
  bool operator<=(
210
  const sub_match<BiIter>& lhs,
211
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
212
 
213
  template <class BiIter>
214
+ bool operator==(const typename iterator_traits<BiIter>::value_type* lhs,
215
  const sub_match<BiIter>& rhs);
216
  template <class BiIter>
217
+ bool operator!=(const typename iterator_traits<BiIter>::value_type* lhs,
218
  const sub_match<BiIter>& rhs);
219
  template <class BiIter>
220
+ bool operator<(const typename iterator_traits<BiIter>::value_type* lhs,
221
  const sub_match<BiIter>& rhs);
222
  template <class BiIter>
223
+ bool operator>(const typename iterator_traits<BiIter>::value_type* lhs,
224
  const sub_match<BiIter>& rhs);
225
  template <class BiIter>
226
+ bool operator>=(const typename iterator_traits<BiIter>::value_type* lhs,
227
  const sub_match<BiIter>& rhs);
228
  template <class BiIter>
229
+ bool operator<=(const typename iterator_traits<BiIter>::value_type* lhs,
230
  const sub_match<BiIter>& rhs);
231
 
232
  template <class BiIter>
233
  bool operator==(const sub_match<BiIter>& lhs,
234
+ const typename iterator_traits<BiIter>::value_type* rhs);
235
  template <class BiIter>
236
  bool operator!=(const sub_match<BiIter>& lhs,
237
+ const typename iterator_traits<BiIter>::value_type* rhs);
238
  template <class BiIter>
239
  bool operator<(const sub_match<BiIter>& lhs,
240
+ const typename iterator_traits<BiIter>::value_type* rhs);
241
  template <class BiIter>
242
  bool operator>(const sub_match<BiIter>& lhs,
243
+ const typename iterator_traits<BiIter>::value_type* rhs);
244
  template <class BiIter>
245
  bool operator>=(const sub_match<BiIter>& lhs,
246
+ const typename iterator_traits<BiIter>::value_type* rhs);
247
  template <class BiIter>
248
  bool operator<=(const sub_match<BiIter>& lhs,
249
+ const typename iterator_traits<BiIter>::value_type* rhs);
250
 
251
  template <class BiIter>
252
+ bool operator==(const typename iterator_traits<BiIter>::value_type& lhs,
253
  const sub_match<BiIter>& rhs);
254
  template <class BiIter>
255
+ bool operator!=(const typename iterator_traits<BiIter>::value_type& lhs,
256
  const sub_match<BiIter>& rhs);
257
  template <class BiIter>
258
+ bool operator<(const typename iterator_traits<BiIter>::value_type& lhs,
259
  const sub_match<BiIter>& rhs);
260
  template <class BiIter>
261
+ bool operator>(const typename iterator_traits<BiIter>::value_type& lhs,
262
  const sub_match<BiIter>& rhs);
263
  template <class BiIter>
264
+ bool operator>=(const typename iterator_traits<BiIter>::value_type& lhs,
265
  const sub_match<BiIter>& rhs);
266
  template <class BiIter>
267
+ bool operator<=(const typename iterator_traits<BiIter>::value_type& lhs,
268
  const sub_match<BiIter>& rhs);
269
 
270
  template <class BiIter>
271
  bool operator==(const sub_match<BiIter>& lhs,
272
+ const typename iterator_traits<BiIter>::value_type& rhs);
273
  template <class BiIter>
274
  bool operator!=(const sub_match<BiIter>& lhs,
275
+ const typename iterator_traits<BiIter>::value_type& rhs);
276
  template <class BiIter>
277
  bool operator<(const sub_match<BiIter>& lhs,
278
+ const typename iterator_traits<BiIter>::value_type& rhs);
279
  template <class BiIter>
280
  bool operator>(const sub_match<BiIter>& lhs,
281
+ const typename iterator_traits<BiIter>::value_type& rhs);
282
  template <class BiIter>
283
  bool operator>=(const sub_match<BiIter>& lhs,
284
+ const typename iterator_traits<BiIter>::value_type& rhs);
285
  template <class BiIter>
286
  bool operator<=(const sub_match<BiIter>& lhs,
287
+ const typename iterator_traits<BiIter>::value_type& rhs);
288
 
289
  template <class charT, class ST, class BiIter>
290
  basic_ostream<charT, ST>&
291
  operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
292
 
293
+ // [re.results], class template match_results
294
  template <class BidirectionalIterator,
295
  class Allocator = allocator<sub_match<BidirectionalIterator>>>
296
  class match_results;
297
 
298
+ using cmatch = match_results<const char*>;
299
+ using wcmatch = match_results<const wchar_t*>;
300
+ using smatch = match_results<string::const_iterator>;
301
+ using wsmatch = match_results<wstring::const_iterator>;
302
 
303
  // match_results comparisons
304
  template <class BidirectionalIterator, class Allocator>
305
  bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
306
  const match_results<BidirectionalIterator, Allocator>& m2);
307
  template <class BidirectionalIterator, class Allocator>
308
  bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
309
  const match_results<BidirectionalIterator, Allocator>& m2);
310
 
311
+ // [re.results.swap], match_results swap
312
  template <class BidirectionalIterator, class Allocator>
313
  void swap(match_results<BidirectionalIterator, Allocator>& m1,
314
  match_results<BidirectionalIterator, Allocator>& m2);
315
 
316
+ // [re.alg.match], function template regex_match
317
+ template <class BidirectionalIterator, class Allocator, class charT, class traits>
 
318
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
319
  match_results<BidirectionalIterator, Allocator>& m,
320
  const basic_regex<charT, traits>& e,
321
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
322
  template <class BidirectionalIterator, class charT, class traits>
323
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
324
  const basic_regex<charT, traits>& e,
325
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
326
  template <class charT, class Allocator, class traits>
327
  bool regex_match(const charT* str, match_results<const charT*, Allocator>& m,
328
  const basic_regex<charT, traits>& e,
329
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
330
  template <class ST, class SA, class Allocator, class charT, class traits>
331
  bool regex_match(const basic_string<charT, ST, SA>& s,
332
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
333
  Allocator>& m,
334
  const basic_regex<charT, traits>& e,
335
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
336
  template <class ST, class SA, class Allocator, class charT, class traits>
337
  bool regex_match(const basic_string<charT, ST, SA>&&,
338
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
339
  Allocator>&,
340
  const basic_regex<charT, traits>&,
341
+ regex_constants::match_flag_type = regex_constants::match_default) = delete;
 
342
  template <class charT, class traits>
343
  bool regex_match(const charT* str,
344
  const basic_regex<charT, traits>& e,
345
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
346
  template <class ST, class SA, class charT, class traits>
347
  bool regex_match(const basic_string<charT, ST, SA>& s,
348
  const basic_regex<charT, traits>& e,
349
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
350
 
351
+ // [re.alg.search], function template regex_search
352
+ template <class BidirectionalIterator, class Allocator, class charT, class traits>
 
353
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
354
  match_results<BidirectionalIterator, Allocator>& m,
355
  const basic_regex<charT, traits>& e,
356
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
357
  template <class BidirectionalIterator, class charT, class traits>
358
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
359
  const basic_regex<charT, traits>& e,
360
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
361
  template <class charT, class Allocator, class traits>
362
  bool regex_search(const charT* str,
363
  match_results<const charT*, Allocator>& m,
364
  const basic_regex<charT, traits>& e,
365
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
366
  template <class charT, class traits>
367
  bool regex_search(const charT* str,
368
  const basic_regex<charT, traits>& e,
369
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
370
  template <class ST, class SA, class charT, class traits>
371
  bool regex_search(const basic_string<charT, ST, SA>& s,
372
  const basic_regex<charT, traits>& e,
373
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
374
  template <class ST, class SA, class Allocator, class charT, class traits>
375
  bool regex_search(const basic_string<charT, ST, SA>& s,
376
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
377
  Allocator>& m,
378
  const basic_regex<charT, traits>& e,
379
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
380
  template <class ST, class SA, class Allocator, class charT, class traits>
381
  bool regex_search(const basic_string<charT, ST, SA>&&,
382
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
383
  Allocator>&,
384
  const basic_regex<charT, traits>&,
385
+ regex_constants::match_flag_type
386
+ = regex_constants::match_default) = delete;
387
 
388
+ // [re.alg.replace], function template regex_replace
389
  template <class OutputIterator, class BidirectionalIterator,
390
  class traits, class charT, class ST, class SA>
391
  OutputIterator
392
  regex_replace(OutputIterator out,
393
  BidirectionalIterator first, BidirectionalIterator last,
394
  const basic_regex<charT, traits>& e,
395
  const basic_string<charT, ST, SA>& fmt,
396
+ regex_constants::match_flag_type flags = regex_constants::match_default);
397
+ template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
 
 
398
  OutputIterator
399
  regex_replace(OutputIterator out,
400
  BidirectionalIterator first, BidirectionalIterator last,
401
  const basic_regex<charT, traits>& e,
402
  const charT* fmt,
403
+ regex_constants::match_flag_type flags = regex_constants::match_default);
404
+ template <class traits, class charT, class ST, class SA, class FST, class FSA>
 
 
405
  basic_string<charT, ST, SA>
406
  regex_replace(const basic_string<charT, ST, SA>& s,
407
  const basic_regex<charT, traits>& e,
408
  const basic_string<charT, FST, FSA>& fmt,
409
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
410
  template <class traits, class charT, class ST, class SA>
411
  basic_string<charT, ST, SA>
412
  regex_replace(const basic_string<charT, ST, SA>& s,
413
  const basic_regex<charT, traits>& e,
414
  const charT* fmt,
415
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
416
  template <class traits, class charT, class ST, class SA>
417
  basic_string<charT>
418
  regex_replace(const charT* s,
419
  const basic_regex<charT, traits>& e,
420
  const basic_string<charT, ST, SA>& fmt,
421
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
422
  template <class traits, class charT>
423
  basic_string<charT>
424
  regex_replace(const charT* s,
425
  const basic_regex<charT, traits>& e,
426
  const charT* fmt,
427
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
428
 
429
+ // [re.regiter], class template regex_iterator
430
  template <class BidirectionalIterator,
431
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
 
432
  class traits = regex_traits<charT>>
433
  class regex_iterator;
434
 
435
+ using cregex_iterator = regex_iterator<const char*>;
436
+ using wcregex_iterator = regex_iterator<const wchar_t*>;
437
+ using sregex_iterator = regex_iterator<string::const_iterator>;
438
+ using wsregex_iterator = regex_iterator<wstring::const_iterator>;
439
 
440
+ // [re.tokiter], class template regex_token_iterator
441
  template <class BidirectionalIterator,
442
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
 
443
  class traits = regex_traits<charT>>
444
  class regex_token_iterator;
445
 
446
+ using cregex_token_iterator = regex_token_iterator<const char*>;
447
+ using wcregex_token_iterator = regex_token_iterator<const wchar_t*>;
448
+ using sregex_token_iterator = regex_token_iterator<string::const_iterator>;
449
+ using wsregex_token_iterator = regex_token_iterator<wstring::const_iterator>;
450
+
451
+ namespace pmr {
452
+ template <class BidirectionalIterator>
453
+ using match_results =
454
+ std::match_results<BidirectionalIterator,
455
+ polymorphic_allocator<sub_match<BidirectionalIterator>>>;
456
+
457
+ using cmatch = match_results<const char*>;
458
+ using wcmatch = match_results<const wchar_t*>;
459
+ using smatch = match_results<string::const_iterator>;
460
+ using wsmatch = match_results<wstring::const_iterator>;
461
+ }
462
  }
463
  ```
464
 
465
  ## Namespace `std::regex_constants` <a id="re.const">[[re.const]]</a>
466
 
 
470
  several constants of these types.
471
 
472
  ### Bitmask type `syntax_option_type` <a id="re.synopt">[[re.synopt]]</a>
473
 
474
  ``` cpp
475
+ namespace std::regex_constants {
476
+ using syntax_option_type = T1;
477
+ inline constexpr syntax_option_type icase = unspecified;
478
+ inline constexpr syntax_option_type nosubs = unspecified;
479
+ inline constexpr syntax_option_type optimize = unspecified;
480
+ inline constexpr syntax_option_type collate = unspecified;
481
+ inline constexpr syntax_option_type ECMAScript = unspecified;
482
+ inline constexpr syntax_option_type basic = unspecified;
483
+ inline constexpr syntax_option_type extended = unspecified;
484
+ inline constexpr syntax_option_type awk = unspecified;
485
+ inline constexpr syntax_option_type grep = unspecified;
486
+ inline constexpr syntax_option_type egrep = unspecified;
487
+ inline constexpr syntax_option_type multiline = unspecified;
 
488
  }
489
  ```
490
 
491
+ The type `syntax_option_type` is an *implementation-defined* bitmask
492
  type ([[bitmask.types]]). Setting its elements has the effects listed
493
+ in Table  [[tab:re:syntaxoption]]. A valid value of type
494
  `syntax_option_type` shall have at most one of the grammar elements
495
  `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep`, set. If no
496
  grammar element is set, the default grammar is `ECMAScript`.
497
 
498
  **Table: `syntax_option_type` effects** <a id="tab:re:syntaxoption">[tab:re:syntaxoption]</a>
 
507
  | % `basic` | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions. \indextext{POSIX!regular expressions}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{basic}}% |
508
  | % `extended` | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions. \indextext{POSIX!extended regular expressions}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{extended}}% |
509
  | % `awk` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX. \indextext{\idxcode{awk}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{awk}}% |
510
  | % `grep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX. \indextext{\idxcode{grep}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{grep}}% |
511
  | % `egrep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX. \indextext{\idxcode{egrep}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{egrep}}% |
512
+ | % `multiline` | Specifies that `\^` shall match the beginning of a line and `$` shall match the end of a line, if the `ECMAScript` engine is selected. \indextext{\idxcode{multiline}}% \indexlibrary{\idxcode{syntax_option_type}!\idxcode{multiline}}% |
513
 
514
 
515
+ ### Bitmask type `match_flag_type` <a id="re.matchflag">[[re.matchflag]]</a>
516
 
517
  ``` cpp
518
+ namespace std::regex_constants {
519
+ using match_flag_type = T2;
520
+ inline constexpr match_flag_type match_default = {};
521
+ inline constexpr match_flag_type match_not_bol = unspecified;
522
+ inline constexpr match_flag_type match_not_eol = unspecified;
523
+ inline constexpr match_flag_type match_not_bow = unspecified;
524
+ inline constexpr match_flag_type match_not_eow = unspecified;
525
+ inline constexpr match_flag_type match_any = unspecified;
526
+ inline constexpr match_flag_type match_not_null = unspecified;
527
+ inline constexpr match_flag_type match_continuous = unspecified;
528
+ inline constexpr match_flag_type match_prev_avail = unspecified;
529
+ inline constexpr match_flag_type format_default = {};
530
+ inline constexpr match_flag_type format_sed = unspecified;
531
+ inline constexpr match_flag_type format_no_copy = unspecified;
532
+ inline constexpr match_flag_type format_first_only = unspecified;
 
 
533
  }
534
  ```
535
 
536
+ The type `match_flag_type` is an *implementation-defined* bitmask type (
537
+ [[bitmask.types]]). The constants of that type, except for
538
+ `match_default` and `format_default`, are bitmask elements. The
539
  `match_default` and `format_default` constants are empty bitmasks.
540
  Matching a regular expression against a sequence of characters
541
  \[`first`, `last`) proceeds according to the rules of the grammar
542
  specified for the regular expression object, modified according to the
543
  effects listed in Table  [[tab:re:matchflag]] for any bitmask elements
 
553
  | % \indexlibrary{\idxcode{match_not_bow}}% `match_not_bow` | The expression \verb|"b"| shall not match the sub-sequence {[}`first`, `first`{)}. |
554
  | % \indexlibrary{\idxcode{match_not_eow}}% `match_not_eow` | The expression \verb|"b"| shall not match the sub-sequence {[}`last`, `last`{)}. |
555
  | % \indexlibrary{\idxcode{match_any}}% `match_any` | If more than one match is possible then any match is an acceptable result. |
556
  | % \indexlibrary{\idxcode{match_not_null}}% `match_not_null` | The expression shall not match an empty sequence. |
557
  | % \indexlibrary{\idxcode{match_continuous}}% `match_continuous` | The expression shall only match a sub-sequence that begins at `first`. |
558
+ | % \indexlibrary{\idxcode{match_prev_avail}}% `match_prev_avail` | \verb!--first! is a valid iterator position. When this flag is set the flags `match_not_bol` and `match_not_bow` shall be ignored by the regular expression algorithms~([[re.alg]]) and iterators~([[re.iter]]). |
559
  | % \indexlibrary{\idxcode{format_default}}% `format_default` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the ECMAScript replace function in ECMA-262, part 15.5.4.11 String.prototype.replace. In addition, during search and replace operations all non-overlapping occurrences of the regular expression shall be located and replaced, and sections of the input that did not match the expression shall be copied unchanged to the output string. |
560
  | % \indexlibrary{\idxcode{format_sed}}% `format_sed` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the sed utility in POSIX. |
561
  | % \indexlibrary{\idxcode{format_no_copy}}% `format_no_copy` | During a search and replace operation, sections of the character container sequence being searched that do not match the regular expression shall not be copied to the output string. |
562
  | % \indexlibrary{\idxcode{format_first_only}}% `format_first_only` | When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced. |
563
 
564
 
565
  ### Implementation-defined `error_type` <a id="re.err">[[re.err]]</a>
566
 
567
  ``` cpp
568
+ namespace std::regex_constants {
569
+ using error_type = T3;
570
+ inline constexpr error_type error_collate = unspecified;
571
+ inline constexpr error_type error_ctype = unspecified;
572
+ inline constexpr error_type error_escape = unspecified;
573
+ inline constexpr error_type error_backref = unspecified;
574
+ inline constexpr error_type error_brack = unspecified;
575
+ inline constexpr error_type error_paren = unspecified;
576
+ inline constexpr error_type error_brace = unspecified;
577
+ inline constexpr error_type error_badbrace = unspecified;
578
+ inline constexpr error_type error_range = unspecified;
579
+ inline constexpr error_type error_space = unspecified;
580
+ inline constexpr error_type error_badrepeat = unspecified;
581
+ inline constexpr error_type error_complexity = unspecified;
582
+ inline constexpr error_type error_stack = unspecified;
 
 
583
  }
584
  ```
585
 
586
  The type `error_type` is an *implementation-defined* enumerated type (
587
  [[enumerated.types]]). Values of type `error_type` represent the error
 
607
 
608
 
609
  ## Class `regex_error` <a id="re.badexp">[[re.badexp]]</a>
610
 
611
  ``` cpp
612
+ class regex_error : public runtime_error {
613
  public:
614
  explicit regex_error(regex_constants::error_type ecode);
615
  regex_constants::error_type code() const;
616
  };
617
  ```
 
623
  regex_error(regex_constants::error_type ecode);
624
  ```
625
 
626
  *Effects:* Constructs an object of class `regex_error`.
627
 
628
+ *Postconditions:* `ecode == code()`.
629
 
630
  ``` cpp
631
  regex_constants::error_type code() const;
632
  ```
633
 
 
637
 
638
  ``` cpp
639
  namespace std {
640
  template <class charT>
641
  struct regex_traits {
642
+ using char_type = charT;
643
+ using string_type = basic_string<char_type>;
644
+ using locale_type = locale;
645
+ using char_class_type = {bitmask_type};
 
646
 
647
  regex_traits();
648
+ static size_t length(const char_type* p);
649
  charT translate(charT c) const;
650
  charT translate_nocase(charT c) const;
651
  template <class ForwardIterator>
652
  string_type transform(ForwardIterator first, ForwardIterator last) const;
653
  template <class ForwardIterator>
 
670
  The specializations `regex_traits<char>` and `regex_traits<wchar_t>`
671
  shall be valid and shall satisfy the requirements for a regular
672
  expression traits class ([[re.req]]).
673
 
674
  ``` cpp
675
+ using char_class_type = bitmask_type;
676
  ```
677
 
678
  The type `char_class_type` is used to represent a character
679
  classification and is capable of holding an implementation specific set
680
  returned by `lookup_classname`.
681
 
682
  ``` cpp
683
+ static size_t length(const char_type* p);
684
  ```
685
 
686
+ *Returns:* `char_traits<charT>::length(p)`.
687
 
688
  ``` cpp
689
  charT translate(charT c) const;
690
  ```
691
 
692
+ *Returns:* `c`.
693
 
694
  ``` cpp
695
  charT translate_nocase(charT c) const;
696
  ```
697
 
 
700
  ``` cpp
701
  template <class ForwardIterator>
702
  string_type transform(ForwardIterator first, ForwardIterator last) const;
703
  ```
704
 
705
+ *Effects:* As if by:
706
 
707
  ``` cpp
708
  string_type str(first, last);
709
  return use_facet<collate<charT>>(
710
  getloc()).transform(&*str.begin(), &*str.begin() + str.length());
 
713
  ``` cpp
714
  template <class ForwardIterator>
715
  string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
716
  ```
717
 
718
+ *Effects:* If
719
+
720
+ ``` cpp
721
+ typeid(use_facet<collate<charT>>) == typeid(collate_byname<charT>)
722
+ ```
723
+
724
  and the form of the sort key returned by
725
+ `collate_byname<charT>::transform(first, last)` is known and can be
726
  converted into a primary sort key then returns that key, otherwise
727
  returns an empty string.
728
 
729
  ``` cpp
730
  template <class ForwardIterator>
 
742
  ForwardIterator first, ForwardIterator last, bool icase = false) const;
743
  ```
744
 
745
  *Returns:* an unspecified value that represents the character
746
  classification named by the character sequence designated by the
747
+ iterator range \[`first`, `last`). If the parameter `icase` is `true`
748
+ then the returned mask identifies the character classification without
749
+ regard to the case of the characters being matched, otherwise it does
750
+ honor the case of the characters being matched.[^1] The value returned
751
+ shall be independent of the case of the characters in the character
752
+ sequence. If the name is not recognized then returns
753
+ `char_class_type()`.
754
 
755
  *Remarks:* For `regex_traits<char>`, at least the narrow character names
756
  in Table  [[tab:re.traits.classnames]] shall be recognized. For
757
  `regex_traits<wchar_t>`, at least the wide character names in
758
  Table  [[tab:re.traits.classnames]] shall be recognized.
 
762
  ```
763
 
764
  *Effects:* Determines if the character `c` is a member of the character
765
  classification represented by `f`.
766
 
767
+ *Returns:* Given the following function declaration:
768
 
769
  ``` cpp
770
  // for exposition only
771
  template<class C>
772
  ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
 
783
  if (ct.is(m, c)) {
784
  return true;
785
  } else if (c == ct.widen('_')) {
786
  charT w[1] = { ct.widen('w') };
787
  char_class_type x = lookup_classname(w, w+1);
 
788
  return (f&x) == x;
789
  } else {
790
  return false;
791
  }
792
  ```
793
 
794
+ [*Example 1*:
795
+
796
  ``` cpp
797
  regex_traits<char> t;
798
  string d("d");
799
  string u("upper");
800
  regex_traits<char>::char_class_type f;
801
  f = t.lookup_classname(d.begin(), d.end());
802
  f |= t.lookup_classname(u.begin(), u.end());
803
  ctype_base::mask m = convert<char>(f); // m == ctype_base::digit|ctype_base::upper
804
  ```
805
 
806
+ — *end example*]
807
+
808
+ [*Example 2*:
809
+
810
  ``` cpp
811
  regex_traits<char> t;
812
  string w("w");
813
  regex_traits<char>::char_class_type f;
814
  f = t.lookup_classname(w.begin(), w.end());
815
  t.isctype('A', f); // returns true
816
  t.isctype('_', f); // returns true
817
  t.isctype(' ', f); // returns false
818
  ```
819
 
820
+ — *end example*]
821
+
822
  ``` cpp
823
  int value(charT ch, int radix) const;
824
  ```
825
 
826
+ *Requires:* The value of `radix` shall be 8, 10, or 16.
827
 
828
+ *Returns:* the value represented by the digit `ch` in base `radix` if
829
+ the character `ch` is a valid digit in base `radix`; otherwise returns
830
+ `-1`.
831
 
832
  ``` cpp
833
  locale_type imbue(locale_type loc);
834
  ```
835
 
836
+ *Effects:* Imbues `this` with a copy of the locale `loc`.
837
+
838
+ [*Note 1*: Calling `imbue` with a different locale than the one
839
+ currently in use invalidates all cached data held by
840
+ `*this`. — *end note*]
841
 
842
  *Returns:* if no locale has been previously imbued then a copy of the
843
  global locale in effect at the time of construction of `*this`,
844
  otherwise a copy of the last argument passed to `imbue`.
845
 
846
+ *Postconditions:* `getloc() == loc`.
847
 
848
  ``` cpp
849
  locale_type getloc() const;
850
  ```
851
 
 
885
 
886
  Objects of type specialization of `basic_regex` are responsible for
887
  converting the sequence of `charT` objects to an internal
888
  representation. It is not specified what form this representation takes,
889
  nor how it is accessed by algorithms that operate on regular
890
+ expressions.
891
+
892
+ [*Note 1*: Implementations will typically declare some function
893
+ templates as friends of `basic_regex` to achieve this — *end note*]
894
 
895
  The functions described in this Clause report errors by throwing
896
  exceptions of type `regex_error`.
897
 
898
  ``` cpp
899
  namespace std {
900
+ template <class charT, class traits = regex_traits<charT>>
 
901
  class basic_regex {
902
  public:
903
  // types:
904
+ using value_type = charT;
905
+ using traits_type = traits;
906
+ using string_type = typename traits::string_type;
907
+ using flag_type = regex_constants::syntax_option_type;
908
+ using locale_type = typename traits::locale_type;
909
 
910
+ // [re.regex.const], constants
911
  static constexpr regex_constants::syntax_option_type
912
  icase = regex_constants::icase;
913
  static constexpr regex_constants::syntax_option_type
914
  nosubs = regex_constants::nosubs;
915
  static constexpr regex_constants::syntax_option_type
 
926
  awk = regex_constants::awk;
927
  static constexpr regex_constants::syntax_option_type
928
  grep = regex_constants::grep;
929
  static constexpr regex_constants::syntax_option_type
930
  egrep = regex_constants::egrep;
931
+ static constexpr regex_constants::syntax_option_type
932
+ multiline = regex_constants::multiline;
933
 
934
+ // [re.regex.construct], construct/copy/destroy
935
  basic_regex();
936
+ explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
 
937
  basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
938
  basic_regex(const basic_regex&);
939
  basic_regex(basic_regex&&) noexcept;
940
  template <class ST, class SA>
941
  explicit basic_regex(const basic_string<charT, ST, SA>& p,
942
  flag_type f = regex_constants::ECMAScript);
943
  template <class ForwardIterator>
944
  basic_regex(ForwardIterator first, ForwardIterator last,
945
  flag_type f = regex_constants::ECMAScript);
946
+ basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
 
947
 
948
  ~basic_regex();
949
 
950
  basic_regex& operator=(const basic_regex&);
951
  basic_regex& operator=(basic_regex&&) noexcept;
952
  basic_regex& operator=(const charT* ptr);
953
  basic_regex& operator=(initializer_list<charT> il);
954
  template <class ST, class SA>
955
  basic_regex& operator=(const basic_string<charT, ST, SA>& p);
956
 
957
+ // [re.regex.assign], assign
958
  basic_regex& assign(const basic_regex& that);
959
  basic_regex& assign(basic_regex&& that) noexcept;
960
+ basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
 
961
  basic_regex& assign(const charT* p, size_t len, flag_type f);
962
  template <class string_traits, class A>
963
  basic_regex& assign(const basic_string<charT, string_traits, A>& s,
964
  flag_type f = regex_constants::ECMAScript);
965
  template <class InputIterator>
966
  basic_regex& assign(InputIterator first, InputIterator last,
967
  flag_type f = regex_constants::ECMAScript);
968
  basic_regex& assign(initializer_list<charT>,
969
  flag_type = regex_constants::ECMAScript);
970
 
971
+ // [re.regex.operations], const operations
972
  unsigned mark_count() const;
973
  flag_type flags() const;
974
 
975
+ // [re.regex.locale], locale
976
  locale_type imbue(locale_type loc);
977
  locale_type getloc() const;
978
 
979
+ // [re.regex.swap], swap
980
  void swap(basic_regex&);
981
  };
982
+
983
+ template<class ForwardIterator>
984
+ basic_regex(ForwardIterator, ForwardIterator,
985
+ regex_constants::syntax_option_type = regex_constants::ECMAScript)
986
+ -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
987
  }
988
  ```
989
 
990
  ### `basic_regex` constants <a id="re.regex.const">[[re.regex.const]]</a>
991
 
992
  ``` cpp
993
+ static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
994
+ static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
995
+ static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
996
+ static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
997
+ static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
998
+ static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
999
+ static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
1000
+ static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
1001
+ static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
1002
+ static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
1003
+ static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
 
 
 
 
 
 
 
 
 
1004
  ```
1005
 
1006
  The static constant members are provided as synonyms for the constants
1007
  declared in namespace `regex_constants`.
1008
 
 
1017
 
1018
  ``` cpp
1019
  explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
1020
  ```
1021
 
1022
+ *Requires:* `p` shall not be a null pointer.
1023
 
1024
+ *Throws:* `regex_error` if `p` is not a valid regular expression.
1025
 
1026
  *Effects:* Constructs an object of class `basic_regex`; the object’s
1027
  internal finite state machine is constructed from the regular expression
1028
  contained in the array of `charT` of length
1029
  `char_traits<charT>::length(p)` whose first element is designated by
1030
+ `p`, and interpreted according to the flags `f`.
1031
 
1032
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1033
  number of marked sub-expressions within the expression.
1034
 
1035
  ``` cpp
1036
  basic_regex(const charT* p, size_t len, flag_type f);
1037
  ```
1038
 
1039
+ *Requires:* `p` shall not be a null pointer.
1040
 
1041
+ *Throws:* `regex_error` if `p` is not a valid regular expression.
1042
 
1043
  *Effects:* Constructs an object of class `basic_regex`; the object’s
1044
  internal finite state machine is constructed from the regular expression
1045
  contained in the sequence of characters \[`p`, `p+len`), and interpreted
1046
+ according the flags specified in `f`.
1047
 
1048
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1049
  number of marked sub-expressions within the expression.
1050
 
1051
  ``` cpp
 
1100
 
1101
  *Postconditions:* `flags()` returns `f`. `mark_count()` returns the
1102
  number of marked sub-expressions within the expression.
1103
 
1104
  ``` cpp
1105
+ basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
 
1106
  ```
1107
 
1108
  *Effects:* Same as `basic_regex(il.begin(), il.end(), f)`.
1109
 
1110
  ### `basic_regex` assign <a id="re.regex.assign">[[re.regex.assign]]</a>
1111
 
1112
  ``` cpp
1113
  basic_regex& operator=(const basic_regex& e);
1114
  ```
1115
 
1116
+ *Effects:* Copies `e` into `*this` and returns `*this`.
1117
+
1118
+ *Postconditions:* `flags()` and `mark_count()` return `e.flags()` and
1119
+ `e.mark_count()`, respectively.
1120
 
1121
  ``` cpp
1122
  basic_regex& operator=(basic_regex&& e) noexcept;
1123
  ```
1124
 
1125
+ *Effects:* Move assigns from `e` into `*this` and returns `*this`.
1126
+
1127
+ *Postconditions:* `flags()` and `mark_count()` return the values that
1128
+ `e.flags()` and `e.mark_count()`, respectively, had before assignment.
1129
+ `e` is in a valid state with unspecified value.
1130
 
1131
  ``` cpp
1132
  basic_regex& operator=(const charT* ptr);
1133
  ```
1134
 
1135
  *Requires:* `ptr` shall not be a null pointer.
1136
 
1137
+ *Effects:* Returns `assign(ptr)`.
1138
 
1139
  ``` cpp
1140
  basic_regex& operator=(initializer_list<charT> il);
1141
  ```
1142
 
1143
+ *Effects:* Returns `assign(il.begin(), il.end())`.
1144
 
1145
  ``` cpp
1146
  template <class ST, class SA>
1147
  basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1148
  ```
1149
 
1150
+ *Effects:* Returns `assign(p)`.
1151
 
1152
  ``` cpp
1153
  basic_regex& assign(const basic_regex& that);
1154
  ```
1155
 
1156
+ *Effects:* Equivalent to `*this = that`.
1157
 
1158
+ *Returns:* `*this`.
 
1159
 
1160
  ``` cpp
1161
  basic_regex& assign(basic_regex&& that) noexcept;
1162
  ```
1163
 
1164
+ *Effects:* Equivalent to `*this = std::move(that)`.
1165
 
1166
+ *Returns:* `*this`.
 
 
1167
 
1168
  ``` cpp
1169
  basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
1170
  ```
1171
 
1172
  *Returns:* `assign(string_type(ptr), f)`.
1173
 
1174
  ``` cpp
1175
+ basic_regex& assign(const charT* ptr, size_t len, flag_type f = regex_constants::ECMAScript);
 
1176
  ```
1177
 
1178
  *Returns:* `assign(string_type(ptr, len), f)`.
1179
 
1180
  ``` cpp
 
1236
  ``` cpp
1237
  locale_type imbue(locale_type loc);
1238
  ```
1239
 
1240
  *Effects:* Returns the result of `traits_inst.imbue(loc)` where
1241
+ `traits_inst` is a (default-initialized) instance of the template type
1242
  argument `traits` stored within the object. After a call to `imbue` the
1243
  `basic_regex` object does not match any character sequence.
1244
 
1245
  ``` cpp
1246
  locale_type getloc() const;
1247
  ```
1248
 
1249
  *Effects:* Returns the result of `traits_inst.getloc()` where
1250
+ `traits_inst` is a (default-initialized) instance of the template
1251
  parameter `traits` stored within the object.
1252
 
1253
  ### `basic_regex` swap <a id="re.regex.swap">[[re.regex.swap]]</a>
1254
 
1255
  ``` cpp
1256
  void swap(basic_regex& e);
1257
  ```
1258
 
1259
  *Effects:* Swaps the contents of the two regular expressions.
1260
 
1261
+ *Postconditions:* `*this` contains the regular expression that was in
1262
+ `e`, `e` contains the regular expression that was in `*this`.
1263
 
1264
  *Complexity:* Constant time.
1265
 
1266
  ### `basic_regex` non-member functions <a id="re.regex.nonmemb">[[re.regex.nonmemb]]</a>
1267
 
 
1280
  a particular marked sub-expression.
1281
 
1282
  ``` cpp
1283
  namespace std {
1284
  template <class BidirectionalIterator>
1285
+ class sub_match : public pair<BidirectionalIterator, BidirectionalIterator> {
1286
  public:
1287
+ using value_type =
1288
+ typename iterator_traits<BidirectionalIterator>::value_type;
1289
+ using difference_type =
1290
+ typename iterator_traits<BidirectionalIterator>::difference_type;
1291
+ using iterator = BidirectionalIterator;
1292
+ using string_type = basic_string<value_type>;
1293
 
1294
  bool matched;
1295
 
1296
  constexpr sub_match();
1297
 
 
1317
 
1318
  ``` cpp
1319
  difference_type length() const;
1320
  ```
1321
 
1322
+ *Returns:* `matched ? distance(first, second) : 0`.
1323
 
1324
  ``` cpp
1325
  operator string_type() const;
1326
  ```
1327
 
1328
+ *Returns:* `matched ? string_type(first, second) : string_type()`.
1329
 
1330
  ``` cpp
1331
  string_type str() const;
1332
  ```
1333
 
1334
+ *Returns:* `matched ? string_type(first, second) : string_type()`.
1335
 
1336
  ``` cpp
1337
  int compare(const sub_match& s) const;
1338
  ```
1339
 
 
1396
  *Returns:* `lhs.compare(rhs) > 0`.
1397
 
1398
  ``` cpp
1399
  template <class BiIter, class ST, class SA>
1400
  bool operator==(
1401
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1402
  const sub_match<BiIter>& rhs);
1403
  ```
1404
 
1405
+ *Returns:*
1406
+
1407
+ ``` cpp
1408
+ rhs.compare(typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) == 0
1409
+ ```
1410
 
1411
  ``` cpp
1412
  template <class BiIter, class ST, class SA>
1413
  bool operator!=(
1414
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1415
  const sub_match<BiIter>& rhs);
1416
  ```
1417
 
1418
  *Returns:* `!(lhs == rhs)`.
1419
 
1420
  ``` cpp
1421
  template <class BiIter, class ST, class SA>
1422
  bool operator<(
1423
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1424
  const sub_match<BiIter>& rhs);
1425
  ```
1426
 
1427
+ *Returns:*
1428
+
1429
+ ``` cpp
1430
+ rhs.compare(typename sub_match<BiIter>::string_type(lhs.data(), lhs.size())) > 0
1431
+ ```
1432
 
1433
  ``` cpp
1434
  template <class BiIter, class ST, class SA>
1435
  bool operator>(
1436
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1437
  const sub_match<BiIter>& rhs);
1438
  ```
1439
 
1440
  *Returns:* `rhs < lhs`.
1441
 
1442
  ``` cpp
1443
  template <class BiIter, class ST, class SA>
1444
  bool operator>=(
1445
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1446
  const sub_match<BiIter>& rhs);
1447
  ```
1448
 
1449
  *Returns:* `!(lhs < rhs)`.
1450
 
1451
  ``` cpp
1452
  template <class BiIter, class ST, class SA>
1453
  bool operator<=(
1454
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
 
1455
  const sub_match<BiIter>& rhs);
1456
  ```
1457
 
1458
  *Returns:* `!(rhs < lhs)`.
1459
 
1460
  ``` cpp
1461
  template <class BiIter, class ST, class SA>
1462
+ bool operator==(
1463
+ const sub_match<BiIter>& lhs,
1464
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1465
  ```
1466
 
1467
+ *Returns:*
1468
+
1469
+ ``` cpp
1470
+ lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0
1471
+ ```
1472
 
1473
  ``` cpp
1474
  template <class BiIter, class ST, class SA>
1475
+ bool operator!=(
1476
+ const sub_match<BiIter>& lhs,
1477
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1478
  ```
1479
 
1480
  *Returns:* `!(lhs == rhs)`.
1481
 
1482
  ``` cpp
1483
  template <class BiIter, class ST, class SA>
1484
+ bool operator<(
1485
+ const sub_match<BiIter>& lhs,
1486
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1487
  ```
1488
 
1489
+ *Returns:*
1490
+
1491
+ ``` cpp
1492
+ lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) < 0
1493
+ ```
1494
 
1495
  ``` cpp
1496
  template <class BiIter, class ST, class SA>
1497
+ bool operator>(
1498
+ const sub_match<BiIter>& lhs,
1499
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1500
  ```
1501
 
1502
  *Returns:* `rhs < lhs`.
1503
 
1504
  ``` cpp
1505
  template <class BiIter, class ST, class SA>
1506
+ bool operator>=(
1507
+ const sub_match<BiIter>& lhs,
1508
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1509
  ```
1510
 
1511
  *Returns:* `!(lhs < rhs)`.
1512
 
1513
  ``` cpp
1514
  template <class BiIter, class ST, class SA>
1515
+ bool operator<=(
1516
+ const sub_match<BiIter>& lhs,
1517
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
1518
  ```
1519
 
1520
  *Returns:* `!(rhs < lhs)`.
1521
 
1522
  ``` cpp
1523
  template <class BiIter>
1524
+ bool operator==(const typename iterator_traits<BiIter>::value_type* lhs,
1525
  const sub_match<BiIter>& rhs);
1526
  ```
1527
 
1528
  *Returns:* `rhs.compare(lhs) == 0`.
1529
 
1530
  ``` cpp
1531
  template <class BiIter>
1532
+ bool operator!=(const typename iterator_traits<BiIter>::value_type* lhs,
1533
  const sub_match<BiIter>& rhs);
1534
  ```
1535
 
1536
  *Returns:* `!(lhs == rhs)`.
1537
 
1538
  ``` cpp
1539
  template <class BiIter>
1540
+ bool operator<(const typename iterator_traits<BiIter>::value_type* lhs,
1541
  const sub_match<BiIter>& rhs);
1542
  ```
1543
 
1544
  *Returns:* `rhs.compare(lhs) > 0`.
1545
 
1546
  ``` cpp
1547
  template <class BiIter>
1548
+ bool operator>(const typename iterator_traits<BiIter>::value_type* lhs,
1549
  const sub_match<BiIter>& rhs);
1550
  ```
1551
 
1552
  *Returns:* `rhs < lhs`.
1553
 
1554
  ``` cpp
1555
  template <class BiIter>
1556
+ bool operator>=(const typename iterator_traits<BiIter>::value_type* lhs,
1557
  const sub_match<BiIter>& rhs);
1558
  ```
1559
 
1560
  *Returns:* `!(lhs < rhs)`.
1561
 
1562
  ``` cpp
1563
  template <class BiIter>
1564
+ bool operator<=(const typename iterator_traits<BiIter>::value_type* lhs,
1565
  const sub_match<BiIter>& rhs);
1566
  ```
1567
 
1568
  *Returns:* `!(rhs < lhs)`.
1569
 
1570
  ``` cpp
1571
  template <class BiIter>
1572
  bool operator==(const sub_match<BiIter>& lhs,
1573
+ const typename iterator_traits<BiIter>::value_type* rhs);
1574
  ```
1575
 
1576
  *Returns:* `lhs.compare(rhs) == 0`.
1577
 
1578
  ``` cpp
1579
  template <class BiIter>
1580
  bool operator!=(const sub_match<BiIter>& lhs,
1581
+ const typename iterator_traits<BiIter>::value_type* rhs);
1582
  ```
1583
 
1584
  *Returns:* `!(lhs == rhs)`.
1585
 
1586
  ``` cpp
1587
  template <class BiIter>
1588
  bool operator<(const sub_match<BiIter>& lhs,
1589
+ const typename iterator_traits<BiIter>::value_type* rhs);
1590
  ```
1591
 
1592
  *Returns:* `lhs.compare(rhs) < 0`.
1593
 
1594
  ``` cpp
1595
  template <class BiIter>
1596
  bool operator>(const sub_match<BiIter>& lhs,
1597
+ const typename iterator_traits<BiIter>::value_type* rhs);
1598
  ```
1599
 
1600
  *Returns:* `rhs < lhs`.
1601
 
1602
  ``` cpp
1603
  template <class BiIter>
1604
  bool operator>=(const sub_match<BiIter>& lhs,
1605
+ const typename iterator_traits<BiIter>::value_type* rhs);
1606
  ```
1607
 
1608
  *Returns:* `!(lhs < rhs)`.
1609
 
1610
  ``` cpp
1611
  template <class BiIter>
1612
  bool operator<=(const sub_match<BiIter>& lhs,
1613
+ const typename iterator_traits<BiIter>::value_type* rhs);
1614
  ```
1615
 
1616
  *Returns:* `!(rhs < lhs)`.
1617
 
1618
  ``` cpp
1619
  template <class BiIter>
1620
+ bool operator==(const typename iterator_traits<BiIter>::value_type& lhs,
1621
  const sub_match<BiIter>& rhs);
1622
  ```
1623
 
1624
  *Returns:*
1625
  `rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) == 0`.
1626
 
1627
  ``` cpp
1628
  template <class BiIter>
1629
+ bool operator!=(const typename iterator_traits<BiIter>::value_type& lhs,
1630
  const sub_match<BiIter>& rhs);
1631
  ```
1632
 
1633
  *Returns:* `!(lhs == rhs)`.
1634
 
1635
  ``` cpp
1636
  template <class BiIter>
1637
+ bool operator<(const typename iterator_traits<BiIter>::value_type& lhs,
1638
  const sub_match<BiIter>& rhs);
1639
  ```
1640
 
1641
  *Returns:*
1642
  `rhs.compare(typename sub_match<BiIter>::string_type(1, lhs)) > 0`.
1643
 
1644
  ``` cpp
1645
  template <class BiIter>
1646
+ bool operator>(const typename iterator_traits<BiIter>::value_type& lhs,
1647
  const sub_match<BiIter>& rhs);
1648
  ```
1649
 
1650
  *Returns:* `rhs < lhs`.
1651
 
1652
  ``` cpp
1653
  template <class BiIter>
1654
+ bool operator>=(const typename iterator_traits<BiIter>::value_type& lhs,
1655
  const sub_match<BiIter>& rhs);
1656
  ```
1657
 
1658
  *Returns:* `!(lhs < rhs)`.
1659
 
1660
  ``` cpp
1661
  template <class BiIter>
1662
+ bool operator<=(const typename iterator_traits<BiIter>::value_type& lhs,
1663
  const sub_match<BiIter>& rhs);
1664
  ```
1665
 
1666
  *Returns:* `!(rhs < lhs)`.
1667
 
1668
  ``` cpp
1669
  template <class BiIter>
1670
  bool operator==(const sub_match<BiIter>& lhs,
1671
+ const typename iterator_traits<BiIter>::value_type& rhs);
1672
  ```
1673
 
1674
  *Returns:*
1675
  `lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0`.
1676
 
1677
  ``` cpp
1678
  template <class BiIter>
1679
  bool operator!=(const sub_match<BiIter>& lhs,
1680
+ const typename iterator_traits<BiIter>::value_type& rhs);
1681
  ```
1682
 
1683
  *Returns:* `!(lhs == rhs)`.
1684
 
1685
  ``` cpp
1686
  template <class BiIter>
1687
  bool operator<(const sub_match<BiIter>& lhs,
1688
+ const typename iterator_traits<BiIter>::value_type& rhs);
1689
  ```
1690
 
1691
  *Returns:*
1692
  `lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) < 0`.
1693
 
1694
  ``` cpp
1695
  template <class BiIter>
1696
  bool operator>(const sub_match<BiIter>& lhs,
1697
+ const typename iterator_traits<BiIter>::value_type& rhs);
1698
  ```
1699
 
1700
  *Returns:* `rhs < lhs`.
1701
 
1702
  ``` cpp
1703
  template <class BiIter>
1704
  bool operator>=(const sub_match<BiIter>& lhs,
1705
+ const typename iterator_traits<BiIter>::value_type& rhs);
1706
  ```
1707
 
1708
  *Returns:* `!(lhs < rhs)`.
1709
 
1710
  ``` cpp
1711
  template <class BiIter>
1712
  bool operator<=(const sub_match<BiIter>& lhs,
1713
+ const typename iterator_traits<BiIter>::value_type& rhs);
1714
  ```
1715
 
1716
  *Returns:* `!(rhs < lhs)`.
1717
 
1718
  ``` cpp
1719
  template <class charT, class ST, class BiIter>
1720
  basic_ostream<charT, ST>&
1721
  operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
1722
  ```
1723
 
1724
+ *Returns:* `os << m.str()`.
1725
 
1726
  ## Class template `match_results` <a id="re.results">[[re.results]]</a>
1727
 
1728
  Class template `match_results` denotes a collection of character
1729
  sequences representing the result of a regular expression match. Storage
1730
  for the collection is allocated and freed as necessary by the member
1731
  functions of class template `match_results`.
1732
 
1733
+ The class template `match_results` satisfies the requirements of an
1734
+ allocator-aware container and of a sequence container (
1735
+ [[container.requirements.general]], [[sequence.reqmts]]) except that
1736
+ only operations defined for const-qualified sequence containers are
1737
+ supported and that the semantics of comparison functions are different
1738
+ from those required for a container.
1739
 
1740
  A default-constructed `match_results` object has no fully established
1741
  result state. A match result is *ready* when, as a consequence of a
1742
  completed regular expression match modifying such an object, its result
1743
  state becomes fully established. The effects of calling most member
1744
  functions from a `match_results` object that is not ready are undefined.
1745
 
1746
  The `sub_match` object stored at index 0 represents sub-expression 0,
1747
  i.e., the whole match. In this case the `sub_match` member `matched` is
1748
+ always `true`. The `sub_match` object stored at index `n` denotes what
1749
  matched the marked sub-expression `n` within the matched expression. If
1750
  the sub-expression `n` participated in a regular expression match then
1751
+ the `sub_match` member `matched` evaluates to `true`, and members
1752
+ `first` and `second` denote the range of characters \[`first`, `second`)
1753
+ which formed that match. Otherwise `matched` is `false`, and members
1754
+ `first` and `second` point to the end of the sequence that was searched.
1755
+
1756
+ [*Note 1*: The `sub_match` objects representing different
1757
+ sub-expressions that did not participate in a regular expression match
1758
+ need not be distinct. — *end note*]
1759
 
1760
  ``` cpp
1761
  namespace std {
1762
  template <class BidirectionalIterator,
1763
  class Allocator = allocator<sub_match<BidirectionalIterator>>>
1764
  class match_results {
1765
  public:
1766
+ using value_type = sub_match<BidirectionalIterator>;
1767
+ using const_reference = const value_type&;
1768
+ using reference = value_type&;
1769
+ using const_iterator = {implementation-defined};
1770
+ using iterator = const_iterator;
1771
+ using difference_type =
1772
+ typename iterator_traits<BidirectionalIterator>::difference_type;
1773
+ using size_type = typename allocator_traits<Allocator>::size_type;
1774
+ using allocator_type = Allocator;
1775
+ using char_type =
1776
+ typename iterator_traits<BidirectionalIterator>::value_type;
1777
+ using string_type = basic_string<char_type>;
1778
 
1779
+ // [re.results.const], construct/copy/destroy
1780
  explicit match_results(const Allocator& a = Allocator());
1781
  match_results(const match_results& m);
1782
  match_results(match_results&& m) noexcept;
1783
  match_results& operator=(const match_results& m);
1784
  match_results& operator=(match_results&& m);
1785
  ~match_results();
1786
 
1787
+ // [re.results.state], state
1788
  bool ready() const;
1789
 
1790
+ // [re.results.size], size
1791
  size_type size() const;
1792
  size_type max_size() const;
1793
  bool empty() const;
1794
 
1795
+ // [re.results.acc], element access
1796
  difference_type length(size_type sub = 0) const;
1797
  difference_type position(size_type sub = 0) const;
1798
  string_type str(size_type sub = 0) const;
1799
  const_reference operator[](size_type n) const;
1800
 
 
1803
  const_iterator begin() const;
1804
  const_iterator end() const;
1805
  const_iterator cbegin() const;
1806
  const_iterator cend() const;
1807
 
1808
+ // [re.results.form], format
1809
  template <class OutputIter>
1810
  OutputIter
1811
  format(OutputIter out,
1812
  const char_type* fmt_first, const char_type* fmt_last,
1813
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
1814
  template <class OutputIter, class ST, class SA>
1815
  OutputIter
1816
  format(OutputIter out,
1817
  const basic_string<char_type, ST, SA>& fmt,
1818
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
1819
  template <class ST, class SA>
1820
  basic_string<char_type, ST, SA>
1821
  format(const basic_string<char_type, ST, SA>& fmt,
1822
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
1823
  string_type
1824
  format(const char_type* fmt,
1825
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
1826
 
1827
+ // [re.results.all], allocator
1828
  allocator_type get_allocator() const;
1829
 
1830
+ // [re.results.swap], swap
1831
  void swap(match_results& that);
1832
  };
1833
  }
1834
  ```
1835
 
 
1856
 
1857
  ``` cpp
1858
  match_results(match_results&& m) noexcept;
1859
  ```
1860
 
1861
+ *Effects:*  Move constructs an object of class `match_results` from `m`
1862
  satisfying the same postconditions as Table  [[tab:re:results:assign]].
1863
  Additionally, the stored `Allocator` value is move constructed from
1864
  `m.get_allocator()`.
1865
 
1866
  *Throws:* Nothing.
 
1908
  size_type size() const;
1909
  ```
1910
 
1911
  *Returns:* One plus the number of marked sub-expressions in the regular
1912
  expression that was matched if `*this` represents the result of a
1913
+ successful match. Otherwise returns `0`.
1914
+
1915
+ [*Note 1*: The state of a `match_results` object can be modified only
1916
+ by passing that object to `regex_match` or `regex_search`.
1917
+ Sections  [[re.alg.match]] and  [[re.alg.search]] specify the effects of
1918
+ those algorithms on their `match_results` arguments. — *end note*]
1919
 
1920
  ``` cpp
1921
  size_type max_size() const;
1922
  ```
1923
 
 
2008
 
2009
  ### `match_results` formatting <a id="re.results.form">[[re.results.form]]</a>
2010
 
2011
  ``` cpp
2012
  template <class OutputIter>
2013
+ OutputIter format(
2014
+ OutputIter out,
2015
  const char_type* fmt_first, const char_type* fmt_last,
2016
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
2017
  ```
2018
 
2019
+ *Requires:* `ready() == true` and `OutputIter` shall satisfy the
2020
  requirements for an Output Iterator ([[output.iterators]]).
2021
 
2022
  *Effects:* Copies the character sequence \[`fmt_first`, `fmt_last`) to
2023
  OutputIter `out`. Replaces each format specifier or escape sequence in
2024
  the copied range with either the character(s) it represents or the
2025
  sequence of characters within `*this` to which it refers. The bitmasks
2026
  specified in `flags` determine which format specifiers and escape
2027
  sequences are recognized.
2028
 
2029
+ *Returns:* `out`.
2030
 
2031
  ``` cpp
2032
  template <class OutputIter, class ST, class SA>
2033
+ OutputIter format(
2034
+ OutputIter out,
2035
  const basic_string<char_type, ST, SA>& fmt,
2036
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
2037
  ```
2038
 
2039
+ *Effects:* Equivalent to:
2040
+
2041
+ ``` cpp
2042
+ return format(out, fmt.data(), fmt.data() + fmt.size(), flags);
2043
+ ```
2044
 
2045
  ``` cpp
2046
  template <class ST, class SA>
2047
+ basic_string<char_type, ST, SA> format(
2048
+ const basic_string<char_type, ST, SA>& fmt,
2049
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
2050
  ```
2051
 
2052
  *Requires:* `ready() == true`.
2053
 
2054
  *Effects:* Constructs an empty string `result` of type
2055
+ `basic_string<char_type, ST, SA>` and calls:
 
2056
 
2057
+ ``` cpp
2058
+ format(back_inserter(result), fmt, flags);
2059
+ ```
2060
+
2061
+ *Returns:* `result`.
2062
 
2063
  ``` cpp
2064
+ string_type format(
2065
+ const char_type* fmt,
2066
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
 
2067
  ```
2068
 
2069
  *Requires:* `ready() == true`.
2070
 
2071
+ *Effects:* Constructs an empty string `result` of type `string_type` and
2072
+ calls:
 
2073
 
2074
+ ``` cpp
2075
+ format(back_inserter(result), fmt, fmt + char_traits<char_type>::length(fmt), flags);
2076
+ ```
2077
+
2078
+ *Returns:* `result`.
2079
 
2080
  ### `match_results` allocator <a id="re.results.all">[[re.results.all]]</a>
2081
 
2082
  ``` cpp
2083
  allocator_type get_allocator() const;
 
2093
  void swap(match_results& that);
2094
  ```
2095
 
2096
  *Effects:* Swaps the contents of the two sequences.
2097
 
2098
+ *Postconditions:* `*this` contains the sequence of matched
2099
+ sub-expressions that were in `that`, `that` contains the sequence of
2100
+ matched sub-expressions that were in `*this`.
2101
 
2102
  *Complexity:* Constant time.
2103
 
2104
  ``` cpp
2105
  template <class BidirectionalIterator, class Allocator>
2106
  void swap(match_results<BidirectionalIterator, Allocator>& m1,
2107
  match_results<BidirectionalIterator, Allocator>& m2);
2108
  ```
2109
 
2110
+ *Effects:* As if by `m1.swap(m2)`.
2111
 
2112
  ### `match_results` non-member functions <a id="re.results.nonmember">[[re.results.nonmember]]</a>
2113
 
2114
  ``` cpp
2115
  template <class BidirectionalIterator, class Allocator>
 
2127
  - `m1.prefix() == m2.prefix()`,
2128
  - `m1.size() == m2.size() && equal(m1.begin(), m1.end(), m2.begin())`,
2129
  and
2130
  - `m1.suffix() == m2.suffix()`.
2131
 
2132
+ [*Note 1*: The algorithm `equal` is defined in
2133
+ Clause  [[algorithms]]. — *end note*]
2134
 
2135
  ``` cpp
2136
  template <class BidirectionalIterator, class Allocator>
2137
  bool operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
2138
  const match_results<BidirectionalIterator, Allocator>& m2);
 
2140
 
2141
  *Returns:* `!(m1 == m2)`.
2142
 
2143
  ## Regular expression algorithms <a id="re.alg">[[re.alg]]</a>
2144
 
2145
+ ### Exceptions <a id="re.except">[[re.except]]</a>
2146
 
2147
  The algorithms described in this subclause may throw an exception of
2148
  type `regex_error`. If such an exception `e` is thrown, `e.code()` shall
2149
  return either `regex_constants::error_complexity` or
2150
  `regex_constants::error_stack`.
 
2154
  ``` cpp
2155
  template <class BidirectionalIterator, class Allocator, class charT, class traits>
2156
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
2157
  match_results<BidirectionalIterator, Allocator>& m,
2158
  const basic_regex<charT, traits>& e,
2159
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2160
  ```
2161
 
2162
  *Requires:* The type `BidirectionalIterator` shall satisfy the
2163
+ requirements of a Bidirectional Iterator ([[bidirectional.iterators]]).
 
2164
 
2165
  *Effects:* Determines whether there is a match between the regular
2166
  expression `e`, and all of the character sequence \[`first`, `last`).
2167
  The parameter `flags` is used to control how the expression is matched
2168
+ against the character sequence. When determining if there is a match,
2169
+ only potential matches that match the entire character sequence are
2170
+ considered. Returns `true` if such a match exists, `false` otherwise.
2171
+
2172
+ [*Example 1*:
2173
+
2174
+ ``` cpp
2175
+ std::regex re("Get|GetValue");
2176
+ std::cmatch m;
2177
+ regex_search("GetValue", m, re); // returns true, and m[0] contains "Get"
2178
+ regex_match ("GetValue", m, re); // returns true, and m[0] contains "GetValue"
2179
+ regex_search("GetValues", m, re); // returns true, and m[0] contains "Get"
2180
+ regex_match ("GetValues", m, re); // returns false
2181
+ ```
2182
+
2183
+ — *end example*]
2184
 
2185
  *Postconditions:* `m.ready() == true` in all cases. If the function
2186
  returns `false`, then the effect on parameter `m` is unspecified except
2187
  that `m.size()` returns `0` and `m.empty()` returns `true`. Otherwise
2188
  the effects on parameter `m` are given in Table  [[tab:re:alg:match]].
 
2190
  **Table: Effects of `regex_match` algorithm** <a id="tab:re:alg:match">[tab:re:alg:match]</a>
2191
 
2192
  | Element | Value |
2193
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2194
  | `m.size()` | `1 + e.mark_count()` |
2195
+ | `m.empty()` | `false` |
2196
+ | `m.prefix().first` | `first` |
2197
+ | `m.prefix().second` | `first` |
2198
+ | `m.prefix().matched` | `false` |
2199
+ | `m.suffix().first` | `last` |
2200
+ | `m.suffix().second` | `last` |
2201
+ | `m.suffix().matched` | `false` |
2202
+ | `m[0].first` | `first` |
2203
+ | `m[0].second` | `last` |
2204
  | `m[0].matched` | `true` |
2205
  | `m[n].first` | For all integers `0 < n < m.size()`, the start of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
2206
  | `m[n].second` | For all integers `0 < n < m.size()`, the end of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
2207
  | `m[n].matched` | For all integers `0 < n < m.size()`, `true` if sub-expression `n` participated in the match, `false` otherwise. |
2208
 
2209
  ``` cpp
2210
  template <class BidirectionalIterator, class charT, class traits>
2211
  bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
2212
  const basic_regex<charT, traits>& e,
2213
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2214
  ```
2215
 
2216
  *Effects:* Behaves “as if” by constructing an instance of
2217
  `match_results<BidirectionalIterator> what`, and then returning the
2218
  result of `regex_match(first, last, what, e, flags)`.
 
2220
  ``` cpp
2221
  template <class charT, class Allocator, class traits>
2222
  bool regex_match(const charT* str,
2223
  match_results<const charT*, Allocator>& m,
2224
  const basic_regex<charT, traits>& e,
2225
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2226
  ```
2227
 
2228
  *Returns:*
2229
  `regex_match(str, str + char_traits<charT>::length(str), m, e, flags)`.
2230
 
2231
  ``` cpp
2232
  template <class ST, class SA, class Allocator, class charT, class traits>
2233
  bool regex_match(const basic_string<charT, ST, SA>& s,
2234
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
2235
  Allocator>& m,
2236
  const basic_regex<charT, traits>& e,
2237
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2238
  ```
2239
 
2240
  *Returns:* `regex_match(s.begin(), s.end(), m, e, flags)`.
2241
 
2242
  ``` cpp
2243
  template <class charT, class traits>
2244
  bool regex_match(const charT* str,
2245
  const basic_regex<charT, traits>& e,
2246
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2247
  ```
2248
 
2249
  *Returns:*
2250
  `regex_match(str, str + char_traits<charT>::length(str), e, flags)`
2251
 
2252
  ``` cpp
2253
  template <class ST, class SA, class charT, class traits>
2254
  bool regex_match(const basic_string<charT, ST, SA>& s,
2255
  const basic_regex<charT, traits>& e,
2256
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2257
  ```
2258
 
2259
  *Returns:* `regex_match(s.begin(), s.end(), e, flags)`.
2260
 
2261
  ### `regex_search` <a id="re.alg.search">[[re.alg.search]]</a>
 
2263
  ``` cpp
2264
  template <class BidirectionalIterator, class Allocator, class charT, class traits>
2265
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
2266
  match_results<BidirectionalIterator, Allocator>& m,
2267
  const basic_regex<charT, traits>& e,
2268
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2269
  ```
2270
 
2271
  *Requires:* Type `BidirectionalIterator` shall satisfy the requirements
2272
  of a Bidirectional Iterator ([[bidirectional.iterators]]).
2273
 
 
2303
 
2304
  ``` cpp
2305
  template <class charT, class Allocator, class traits>
2306
  bool regex_search(const charT* str, match_results<const charT*, Allocator>& m,
2307
  const basic_regex<charT, traits>& e,
2308
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2309
  ```
2310
 
2311
+ *Returns:*
2312
  `regex_search(str, str + char_traits<charT>::length(str), m, e, flags)`.
2313
 
2314
  ``` cpp
2315
  template <class ST, class SA, class Allocator, class charT, class traits>
2316
  bool regex_search(const basic_string<charT, ST, SA>& s,
2317
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
 
2318
  Allocator>& m,
2319
  const basic_regex<charT, traits>& e,
2320
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2321
  ```
2322
 
2323
+ *Returns:* `regex_search(s.begin(), s.end(), m, e, flags)`.
 
2324
 
2325
  ``` cpp
2326
  template <class BidirectionalIterator, class charT, class traits>
2327
  bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
2328
  const basic_regex<charT, traits>& e,
2329
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2330
  ```
2331
 
2332
  *Effects:* Behaves “as if” by constructing an object `what` of type
2333
+ `match_results<BidirectionalIterator>` and returning
2334
  `regex_search(first, last, what, e, flags)`.
2335
 
2336
  ``` cpp
2337
  template <class charT, class traits>
2338
  bool regex_search(const charT* str,
2339
  const basic_regex<charT, traits>& e,
2340
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2341
  ```
2342
 
2343
  *Returns:*
2344
+ `regex_search(str, str + char_traits<charT>::length(str), e, flags)`.
2345
 
2346
  ``` cpp
2347
  template <class ST, class SA, class charT, class traits>
2348
  bool regex_search(const basic_string<charT, ST, SA>& s,
2349
  const basic_regex<charT, traits>& e,
2350
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2351
  ```
2352
 
2353
  *Returns:* `regex_search(s.begin(), s.end(), e, flags)`.
2354
 
2355
  ### `regex_replace` <a id="re.alg.replace">[[re.alg.replace]]</a>
 
2360
  OutputIterator
2361
  regex_replace(OutputIterator out,
2362
  BidirectionalIterator first, BidirectionalIterator last,
2363
  const basic_regex<charT, traits>& e,
2364
  const basic_string<charT, ST, SA>& fmt,
2365
+ regex_constants::match_flag_type flags = regex_constants::match_default);
2366
+ template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
 
 
2367
  OutputIterator
2368
  regex_replace(OutputIterator out,
2369
  BidirectionalIterator first, BidirectionalIterator last,
2370
  const basic_regex<charT, traits>& e,
2371
  const charT* fmt,
2372
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2373
  ```
2374
 
2375
  *Effects:* Constructs a `regex_iterator` object `i` as if by
2376
 
2377
  ``` cpp
 
2379
  ```
2380
 
2381
  and uses `i` to enumerate through all of the matches `m` of type
2382
  `match_results<BidirectionalIterator>` that occur within the sequence
2383
  \[`first`, `last`). If no such matches are found and
2384
+ `!(flags & regex_constants::format_no_copy)`, then calls
2385
 
2386
  ``` cpp
2387
+ out = copy(first, last, out)
2388
  ```
2389
 
2390
  If any matches are found then, for each such match:
2391
 
2392
  - If `!(flags & regex_constants::format_no_copy)`, calls
2393
  ``` cpp
2394
+ out = copy(m.prefix().first, m.prefix().second, out)
2395
  ```
2396
  - Then calls
2397
  ``` cpp
2398
  out = m.format(out, fmt, flags)
2399
  ```
 
2407
 
2408
  Finally, if such a match is found and
2409
  `!(flags & regex_constants::format_no_copy)`, calls
2410
 
2411
  ``` cpp
2412
+ out = copy(last_m.suffix().first, last_m.suffix().second, out)
2413
  ```
2414
 
2415
  where `last_m` is a copy of the last match found. If
2416
+ `flags & regex_constants::format_first_only` is nonzero, then only the
2417
  first match found is replaced.
2418
 
2419
  *Returns:* `out`.
2420
 
2421
  ``` cpp
2422
  template <class traits, class charT, class ST, class SA, class FST, class FSA>
2423
  basic_string<charT, ST, SA>
2424
  regex_replace(const basic_string<charT, ST, SA>& s,
2425
  const basic_regex<charT, traits>& e,
2426
  const basic_string<charT, FST, FSA>& fmt,
2427
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2428
  template <class traits, class charT, class ST, class SA>
2429
  basic_string<charT, ST, SA>
2430
  regex_replace(const basic_string<charT, ST, SA>& s,
2431
  const basic_regex<charT, traits>& e,
2432
  const charT* fmt,
2433
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2434
  ```
2435
 
2436
  *Effects:* Constructs an empty string `result` of type
2437
+ `basic_string<charT, ST, SA>` and calls:
 
2438
 
2439
+ ``` cpp
2440
+ regex_replace(back_inserter(result), s.begin(), s.end(), e, fmt, flags);
2441
+ ```
2442
+
2443
+ *Returns:* `result`.
2444
 
2445
  ``` cpp
2446
  template <class traits, class charT, class ST, class SA>
2447
  basic_string<charT>
2448
  regex_replace(const charT* s,
2449
  const basic_regex<charT, traits>& e,
2450
  const basic_string<charT, ST, SA>& fmt,
2451
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2452
  template <class traits, class charT>
2453
  basic_string<charT>
2454
  regex_replace(const charT* s,
2455
  const basic_regex<charT, traits>& e,
2456
  const charT* fmt,
2457
+ regex_constants::match_flag_type flags = regex_constants::match_default);
 
2458
  ```
2459
 
2460
  *Effects:* Constructs an empty string `result` of type
2461
+ `basic_string<charT>` and calls:
 
2462
 
2463
+ ``` cpp
2464
+ regex_replace(back_inserter(result), s, s + char_traits<charT>::length(s), e, fmt, flags);
2465
+ ```
2466
+
2467
+ *Returns:* `result`.
2468
 
2469
  ## Regular expression iterators <a id="re.iter">[[re.iter]]</a>
2470
 
2471
  ### Class template `regex_iterator` <a id="re.regiter">[[re.regiter]]</a>
2472
 
 
2492
  iterators are equal when they are constructed from the same arguments.
2493
 
2494
  ``` cpp
2495
  namespace std {
2496
  template <class BidirectionalIterator,
2497
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
 
2498
  class traits = regex_traits<charT>>
2499
  class regex_iterator {
2500
  public:
2501
+ using regex_type = basic_regex<charT, traits>;
2502
+ using iterator_category = forward_iterator_tag;
2503
+ using value_type = match_results<BidirectionalIterator>;
2504
+ using difference_type = ptrdiff_t;
2505
+ using pointer = const value_type*;
2506
+ using reference = const value_type&;
2507
 
2508
  regex_iterator();
2509
  regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
2510
  const regex_type& re,
2511
+ regex_constants::match_flag_type m = regex_constants::match_default);
2512
+ regex_iterator(BidirectionalIterator, BidirectionalIterator,
2513
+ const regex_type&&,
2514
+ regex_constants::match_flag_type = regex_constants::match_default) = delete;
 
 
2515
  regex_iterator(const regex_iterator&);
2516
  regex_iterator& operator=(const regex_iterator&);
2517
  bool operator==(const regex_iterator&) const;
2518
  bool operator!=(const regex_iterator&) const;
2519
  const value_type& operator*() const;
2520
  const value_type* operator->() const;
2521
  regex_iterator& operator++();
2522
  regex_iterator operator++(int);
2523
+
2524
  private:
2525
  BidirectionalIterator begin; // exposition only
2526
  BidirectionalIterator end; // exposition only
2527
  const regex_type* pregex; // exposition only
2528
  regex_constants::match_flag_type flags; // exposition only
 
2531
  }
2532
  ```
2533
 
2534
  An object of type `regex_iterator` that is not an end-of-sequence
2535
  iterator holds a *zero-length match* if `match[0].matched == true` and
2536
+ `match[0].first == match[0].second`.
2537
+
2538
+ [*Note 1*: For example, this can occur when the part of the regular
2539
+ expression that matched consists only of an assertion (such as `'^'`,
2540
+ `'$'`, `'\b'`, `'\B'`). — *end note*]
2541
 
2542
  #### `regex_iterator` constructors <a id="re.regiter.cnstr">[[re.regiter.cnstr]]</a>
2543
 
2544
  ``` cpp
2545
  regex_iterator();
 
2607
 
2608
  If the iterator holds a zero-length match and `start == end` the
2609
  operator sets `*this` to the end-of-sequence iterator and returns
2610
  `*this`.
2611
 
2612
+ Otherwise, if the iterator holds a zero-length match, the operator
2613
+ calls:
2614
+
2615
+ ``` cpp
2616
+ regex_search(start, end, match, *pregex,
2617
+ flags | regex_constants::match_not_null | regex_constants::match_continuous)
2618
+ ```
2619
+
2620
+ If the call returns `true` the operator returns `*this`. Otherwise the
2621
+ operator increments `start` and continues as if the most recent match
2622
+ was not a zero-length match.
2623
 
2624
  If the most recent match was not a zero-length match, the operator sets
2625
+ `flags` to `flags | regex_constants::match_prev_avail` and calls
2626
  `regex_search(start, end, match, *pregex, flags)`. If the call returns
2627
  `false` the iterator sets `*this` to the end-of-sequence iterator. The
2628
  iterator then returns `*this`.
2629
 
2630
  In all cases in which the call to `regex_search` returns `true`,
2631
  `match.prefix().first` shall be equal to the previous value of
2632
  `match[0].second`, and for each index `i` in the half-open range
2633
+ `[0, match.size())` for which `match[i].matched` is `true`,
2634
+ `match.position(i)` shall return `distance(begin, match[i].first)`.
2635
 
2636
+ [*Note 1*: This means that `match.position(i)` gives the offset from
2637
+ the beginning of the target sequence, which is often not the same as the
2638
+ offset from the sequence passed in the call to
2639
+ `regex_search`. — *end note*]
2640
 
2641
  It is unspecified how the implementation makes these adjustments.
2642
 
2643
+ [*Note 2*: This means that a compiler may call an
2644
+ implementation-specific search function, in which case a user-defined
2645
+ specialization of `regex_search` will not be called. — *end note*]
2646
 
2647
  ``` cpp
2648
  regex_iterator operator++(int);
2649
  ```
2650
 
2651
+ *Effects:* As if by:
2652
 
2653
  ``` cpp
2654
  regex_iterator tmp = *this;
2655
  ++(*this);
2656
  return tmp;
 
2702
  iterators are equal when they are constructed from the same arguments.
2703
 
2704
  ``` cpp
2705
  namespace std {
2706
  template <class BidirectionalIterator,
2707
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
 
2708
  class traits = regex_traits<charT>>
2709
  class regex_token_iterator {
2710
  public:
2711
+ using regex_type = basic_regex<charT, traits>;
2712
+ using iterator_category = forward_iterator_tag;
2713
+ using value_type = sub_match<BidirectionalIterator>;
2714
+ using difference_type = ptrdiff_t;
2715
+ using pointer = const value_type*;
2716
+ using reference = const value_type&;
2717
 
2718
  regex_token_iterator();
2719
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2720
  const regex_type& re,
2721
  int submatch = 0,
2722
  regex_constants::match_flag_type m =
2723
  regex_constants::match_default);
2724
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2725
  const regex_type& re,
2726
+ const vector<int>& submatches,
2727
  regex_constants::match_flag_type m =
2728
  regex_constants::match_default);
2729
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2730
  const regex_type& re,
2731
  initializer_list<int> submatches,
2732
  regex_constants::match_flag_type m =
2733
  regex_constants::match_default);
2734
+ template <size_t N>
2735
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2736
  const regex_type& re,
2737
  const int (&submatches)[N],
2738
  regex_constants::match_flag_type m =
2739
  regex_constants::match_default);
 
2742
  int submatch = 0,
2743
  regex_constants::match_flag_type m =
2744
  regex_constants::match_default) = delete;
2745
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2746
  const regex_type&& re,
2747
+ const vector<int>& submatches,
2748
  regex_constants::match_flag_type m =
2749
  regex_constants::match_default) = delete;
2750
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2751
  const regex_type&& re,
2752
  initializer_list<int> submatches,
2753
  regex_constants::match_flag_type m =
2754
  regex_constants::match_default) = delete;
2755
+ template <size_t N>
2756
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2757
  const regex_type&& re,
2758
  const int (&submatches)[N],
2759
  regex_constants::match_flag_type m =
2760
  regex_constants::match_default) = delete;
 
2764
  bool operator!=(const regex_token_iterator&) const;
2765
  const value_type& operator*() const;
2766
  const value_type* operator->() const;
2767
  regex_token_iterator& operator++();
2768
  regex_token_iterator operator++(int);
2769
+
2770
  private:
2771
+ using position_iterator =
2772
+ regex_iterator<BidirectionalIterator, charT, traits>; // exposition only
2773
  position_iterator position; // exposition only
2774
  const value_type* result; // exposition only
2775
  value_type suffix; // exposition only
2776
+ size_t N; // exposition only
2777
+ vector<int> subs; // exposition only
2778
  };
2779
  }
2780
  ```
2781
 
2782
  A *suffix iterator* is a `regex_token_iterator` object that points to a
 
2784
  suffix iterator the member `result` holds a pointer to the data member
2785
  `suffix`, the value of the member `suffix.match` is `true`,
2786
  `suffix.first` points to the beginning of the final sequence, and
2787
  `suffix.second` points to the end of the final sequence.
2788
 
2789
+ [*Note 1*: For a suffix iterator, data member `suffix.first` is the
2790
+ same as the end of the last match found, and `suffix.second` is the same
2791
+ as the end of the target sequence — *end note*]
2792
 
2793
  The *current match* is `(*position).prefix()` if `subs[N] == -1`, or
2794
  `(*position)[subs[N]]` for any other value of `subs[N]`.
2795
 
2796
  #### `regex_token_iterator` constructors <a id="re.tokiter.cnstr">[[re.tokiter.cnstr]]</a>
 
2803
 
2804
  ``` cpp
2805
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2806
  const regex_type& re,
2807
  int submatch = 0,
2808
+ regex_constants::match_flag_type m = regex_constants::match_default);
 
2809
 
2810
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2811
  const regex_type& re,
2812
+ const vector<int>& submatches,
2813
+ regex_constants::match_flag_type m = regex_constants::match_default);
 
2814
 
2815
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2816
  const regex_type& re,
2817
  initializer_list<int> submatches,
2818
+ regex_constants::match_flag_type m = regex_constants::match_default);
 
2819
 
2820
+ template <size_t N>
2821
  regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
2822
  const regex_type& re,
2823
  const int (&submatches)[N],
2824
+ regex_constants::match_flag_type m = regex_constants::match_default);
 
2825
  ```
2826
 
2827
  *Requires:* Each of the initialization values of `submatches` shall be
2828
  `>= -1`.
2829
 
 
2934
  -
2935
  ClassAtomNoDash
2936
  ClassAtomExClass
2937
  ClassAtomCollatingElement
2938
  ClassAtomEquivalence
2939
+
2940
+ IdentityEscape ::
2941
+ SourceCharacter but not c
2942
  ```
2943
 
2944
  The following new productions are then added:
2945
 
2946
  ``` cpp
 
3009
  machine contains an invalid class name the translator shall throw an
3010
  exception object of type `regex_error`.
3011
 
3012
  If the *CV* of a *UnicodeEscapeSequence* is greater than the largest
3013
  value that can be held in an object of type `charT` the translator shall
3014
+ throw an exception object of type `regex_error`.
3015
+
3016
+ [*Note 1*: This means that values of the form `"uxxxx"` that do not fit
3017
+ in a character are invalid. — *end note*]
3018
 
3019
  Where the regular expression grammar requires the conversion of a
3020
  sequence of characters to an integral value, this is accomplished by
3021
  calling `traits_inst.value`.
3022
 
3023
  The behavior of the internal finite state machine representation when
3024
  used to match a sequence of characters is as described in ECMA-262. The
3025
+ behavior is modified according to any match_flag_type flags (
3026
+ [[re.matchflag]]) specified when using the regular expression object in
3027
+ one of the regular expression algorithms ([[re.alg]]). The behavior is
3028
  also localized by interaction with the traits class template parameter
3029
  as follows:
3030
 
3031
  - During matching of a regular expression finite state machine against a
3032
  sequence of characters, two characters `c` and `d` are compared using
3033
  the following rules:
3034
+ - if `(flags() & regex_constants::icase)` the two characters are equal
3035
+ if
3036
  `traits_inst.translate_nocase(c) == traits_inst.translate_nocase(d)`;
3037
+ - otherwise, if `flags() & regex_constants::collate` the two
3038
  characters are equal if
3039
  `traits_inst.translate(c) == traits_inst.translate(d)`;
3040
+ - otherwise, the two characters are equal if `c == d`.
3041
  - During matching of a regular expression finite state machine against a
3042
  sequence of characters, comparison of a collating element range
3043
  `c1-c2` against a character `c` is conducted as follows: if
3044
+ `flags() & regex_constants::collate` is false then the character `c`
3045
+ is matched if `c1
3046
  <= c && c <= c2`, otherwise `c` is matched in accordance with the
3047
  following algorithm:
3048
  ``` cpp
3049
  string_type str1 = string_type(1,
3050
  flags() & icase ?
 
3074
 
3075
  <!-- Link reference definitions -->
3076
  [algorithms]: algorithms.md#algorithms
3077
  [bidirectional.iterators]: iterators.md#bidirectional.iterators
3078
  [bitmask.types]: library.md#bitmask.types
3079
+ [container.requirements.general]: containers.md#container.requirements.general
3080
  [enumerated.types]: library.md#enumerated.types
3081
  [forward.iterators]: iterators.md#forward.iterators
3082
  [input.iterators]: iterators.md#input.iterators
3083
  [output.iterators]: iterators.md#output.iterators
3084
  [re]: #re
 
3129
  [re.tokiter.comp]: #re.tokiter.comp
3130
  [re.tokiter.deref]: #re.tokiter.deref
3131
  [re.tokiter.incr]: #re.tokiter.incr
3132
  [re.traits]: #re.traits
3133
  [sequence.reqmts]: containers.md#sequence.reqmts
3134
+ [strings.general]: strings.md#strings.general
3135
  [tab:re.lib.summary]: #tab:re.lib.summary
3136
  [tab:re.traits.classnames]: #tab:re.traits.classnames
3137
  [tab:re:RegexpTraits]: #tab:re:RegexpTraits
3138
  [tab:re:alg:match]: #tab:re:alg:match
3139
  [tab:re:alg:search]: #tab:re:alg:search
3140
  [tab:re:errortype]: #tab:re:errortype
3141
  [tab:re:matchflag]: #tab:re:matchflag
3142
  [tab:re:results:assign]: #tab:re:results:assign
3143
  [tab:re:syntaxoption]: #tab:re:syntaxoption
3144
 
3145
+ [^1]: For example, if the parameter `icase` is `true` then `[[:lower:]]`
3146
  is the same as `[[:alpha:]]`.