libstdc++: regex_constants.h Source File

libstdc++

regex_constants.h
Go to the documentation of this file.
1// Namespace std::regex_constants -*- C++ -*-
2
3// Copyright (C) 2010-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/**
26 * @file bits/regex_constants.h
27 * @brief Constant definitions for the std regex library.
28 *
29 * This is an internal header file, included by other library headers.
30 * Do not attempt to use it directly. @headername{regex}
31 */
32
33namespace std _GLIBCXX_VISIBILITY(default)
34{
35_GLIBCXX_BEGIN_NAMESPACE_VERSION
36
37/**
38 * @defgroup regex Regular Expressions
39 *
40 * A facility for performing regular expression pattern matching.
41 *
42 * @since C++11
43 *
44 * @{
45 */
46
47/**
48 * @namespace std::regex_constants
49 * @brief ISO C++ 2011 namespace for options and flags used with std::regex
50 */
51namespace regex_constants
52{
53 /**
54 * @name 5.1 Regular Expression Syntax Options
55 */
56 ///@{
57
58 /**
59 * @brief This is a bitmask type indicating how to interpret the regex.
60 *
61 * The @c syntax_option_type is implementation defined but it is valid to
62 * perform bitwise operations on these values and expect the right thing to
63 * happen.
64 *
65 * A valid value of type syntax_option_type shall have exactly one of the
66 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
67 * %set.
68 */
69 enum [[__gnu__::__flag_enum__]] syntax_option_type : unsigned int
70 {
71 _S_icase = 1 << 0,
72 _S_nosubs = 1 << 1,
73 _S_optimize = 1 << 2,
74 _S_collate = 1 << 3,
75 _S_ECMAScript = 1 << 4,
76 _S_basic = 1 << 5,
77 _S_extended = 1 << 6,
78 _S_awk = 1 << 7,
79 _S_grep = 1 << 8,
80 _S_egrep = 1 << 9,
81 _S_polynomial = 1 << 10,
82 _S_multiline = 1 << 11
83 };
84
85 /**
86 * Specifies that the matching of regular expressions against a character
87 * sequence shall be performed without regard to case.
88 */
89 _GLIBCXX17_INLINE constexpr syntax_option_type icase = _S_icase;
90
91 /**
92 * Specifies that when a regular expression is matched against a character
93 * container sequence, no sub-expression matches are to be stored in the
94 * supplied match_results structure.
95 */
96 _GLIBCXX17_INLINE constexpr syntax_option_type nosubs = _S_nosubs;
97
98 /**
99 * Specifies that the regular expression engine should pay more attention to
100 * the speed with which regular expressions are matched, and less to the
101 * speed with which regular expression objects are constructed. Otherwise
102 * it has no detectable effect on the program output.
103 */
104 _GLIBCXX17_INLINE constexpr syntax_option_type optimize = _S_optimize;
105
106 /**
107 * Specifies that character ranges of the form [a-b] should be locale
108 * sensitive.
109 */
110 _GLIBCXX17_INLINE constexpr syntax_option_type collate = _S_collate;
111
112 /**
113 * Specifies that the grammar recognized by the regular expression engine is
114 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
115 * Language Specification, Standard Ecma-262, third edition, 1999], as
116 * modified in section [28.13]. This grammar is similar to that defined
117 * in the PERL scripting language but extended with elements found in the
118 * POSIX regular expression grammar.
119 */
120 _GLIBCXX17_INLINE constexpr syntax_option_type ECMAScript = _S_ECMAScript;
121
122 /**
123 * Specifies that the grammar recognized by the regular expression engine is
124 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
125 * Portable Operating System Interface (POSIX), Base Definitions and
126 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
127 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
128 */
129 _GLIBCXX17_INLINE constexpr syntax_option_type basic = _S_basic;
130
131 /**
132 * Specifies that the grammar recognized by the regular expression engine is
133 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
134 * Portable Operating System Interface (POSIX), Base Definitions and
135 * Headers, Section 9, Regular Expressions.
136 */
137 _GLIBCXX17_INLINE constexpr syntax_option_type extended = _S_extended;
138
139 /**
140 * Specifies that the grammar recognized by the regular expression engine is
141 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
142 * identical to syntax_option_type extended, except that C-style escape
143 * sequences are supported. These sequences are:
144 * \\\\, \\a, \\b, \\f, \\n, \\r, \\t , \\v, \\&apos,, &apos,,
145 * and \\ddd (where ddd is one, two, or three octal digits).
146 */
147 _GLIBCXX17_INLINE constexpr syntax_option_type awk = _S_awk;
148
149 /**
150 * Specifies that the grammar recognized by the regular expression engine is
151 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
152 * identical to syntax_option_type basic, except that newlines are treated
153 * as whitespace.
154 */
155 _GLIBCXX17_INLINE constexpr syntax_option_type grep = _S_grep;
156
157 /**
158 * Specifies that the grammar recognized by the regular expression engine is
159 * that used by POSIX utility grep when given the -E option in
160 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
161 * extended, except that newlines are treated as whitespace.
162 */
163 _GLIBCXX17_INLINE constexpr syntax_option_type egrep = _S_egrep;
164
165#if __cplusplus >= 201703L || !defined __STRICT_ANSI__
166 // _GLIBCXX_RESOLVE_LIB_DEFECTS
167 // 2503. multiline option should be added to syntax_option_type
168 /**
169 * Specifies that the `^` anchor matches at the beginning of a line,
170 * and the `$` anchor matches at the end of a line, not only at the
171 * beginning/end of the input.
172 * Valid for the ECMAScript syntax, ignored otherwise.
173 * @since C++17
174 */
175 _GLIBCXX17_INLINE constexpr syntax_option_type multiline = _S_multiline;
176#endif
177
178 /// Extension: Equivalent to regex_constants::multiline for C++11 and C++14.
179 _GLIBCXX17_INLINE constexpr syntax_option_type __multiline = _S_multiline;
180
181 /**
182 * Extension: Ensure both space complexity of compiled regex and
183 * time complexity execution are not exponential.
184 * If specified in a regex with back-references, the exception
185 * regex_constants::error_complexity will be thrown.
186 */
187 _GLIBCXX17_INLINE constexpr syntax_option_type __polynomial = _S_polynomial;
188
189 [[__nodiscard__]]
190 constexpr syntax_option_type
191 operator&(syntax_option_type __a, syntax_option_type __b) noexcept
192 {
193 return (syntax_option_type)(static_cast<unsigned int>(__a)
194 & static_cast<unsigned int>(__b));
195 }
196
197 [[__nodiscard__]]
198 constexpr syntax_option_type
199 operator|(syntax_option_type __a, syntax_option_type __b) noexcept
200 {
201 return (syntax_option_type)(static_cast<unsigned int>(__a)
202 | static_cast<unsigned int>(__b));
203 }
204
205 [[__nodiscard__]]
206 constexpr syntax_option_type
207 operator^(syntax_option_type __a, syntax_option_type __b) noexcept
208 {
209 return (syntax_option_type)(static_cast<unsigned int>(__a)
210 ^ static_cast<unsigned int>(__b));
211 }
212
213 [[__nodiscard__]]
214 constexpr syntax_option_type
215 operator~(syntax_option_type __a) noexcept
216 { return (syntax_option_type)(~static_cast<unsigned int>(__a)); }
217
218 _GLIBCXX14_CONSTEXPR
219 inline syntax_option_type&
220 operator&=(syntax_option_type& __a, syntax_option_type __b) noexcept
221 { return __a = __a & __b; }
222
223 _GLIBCXX14_CONSTEXPR
224 inline syntax_option_type&
225 operator|=(syntax_option_type& __a, syntax_option_type __b) noexcept
226 { return __a = __a | __b; }
227
228 _GLIBCXX14_CONSTEXPR
229 inline syntax_option_type&
230 operator^=(syntax_option_type& __a, syntax_option_type __b) noexcept
231 { return __a = __a ^ __b; }
232
233 ///@}
234
235 /**
236 * @name 5.2 Matching Rules
237 *
238 * Matching a regular expression against a sequence of characters [first,
239 * last) proceeds according to the rules of the grammar specified for the
240 * regular expression object, modified according to the effects listed
241 * below for any bitmask elements set.
242 *
243 */
244 ///@{
245
246 /**
247 * @brief This is a bitmask type indicating regex matching rules.
248 *
249 * The @c match_flag_type is implementation defined but it is valid to
250 * perform bitwise operations on these values and expect the right thing to
251 * happen.
252 */
253 enum match_flag_type : unsigned int
254 {
255 _S_default,
256 _S_not_bol = 1 << 0,
257 _S_not_eol = 1 << 1,
258 _S_not_bow = 1 << 2,
259 _S_not_eow = 1 << 3,
260 _S_any = 1 << 4,
261 _S_not_null = 1 << 5,
262 _S_continuous = 1 << 6,
263 _S_prev_avail = 1 << 7,
264 _S_sed = 1 << 8,
265 _S_no_copy = 1 << 9,
266 _S_first_only = 1 << 10,
267 _S_match_flag_last = 1 << 11
268 };
269
270 /**
271 * The default matching rules.
272 */
273 _GLIBCXX17_INLINE constexpr match_flag_type match_default = _S_default;
274
275 /**
276 * The first character in the sequence [first, last) is treated as though it
277 * is not at the beginning of a line, so the character (^) in the regular
278 * expression shall not match [first, first).
279 */
280 _GLIBCXX17_INLINE constexpr match_flag_type match_not_bol = _S_not_bol;
281
282 /**
283 * The last character in the sequence [first, last) is treated as though it
284 * is not at the end of a line, so the character ($) in the regular
285 * expression shall not match [last, last).
286 */
287 _GLIBCXX17_INLINE constexpr match_flag_type match_not_eol = _S_not_eol;
288
289 /**
290 * The expression \\b is not matched against the sub-sequence
291 * [first,first).
292 */
293 _GLIBCXX17_INLINE constexpr match_flag_type match_not_bow = _S_not_bow;
294
295 /**
296 * The expression \\b should not be matched against the sub-sequence
297 * [last,last).
298 */
299 _GLIBCXX17_INLINE constexpr match_flag_type match_not_eow = _S_not_eow;
300
301 /**
302 * If more than one match is possible then any match is an acceptable
303 * result.
304 */
305 _GLIBCXX17_INLINE constexpr match_flag_type match_any = _S_any;
306
307 /**
308 * The expression does not match an empty sequence.
309 */
310 _GLIBCXX17_INLINE constexpr match_flag_type match_not_null = _S_not_null;
311
312 /**
313 * The expression only matches a sub-sequence that begins at first .
314 */
315 _GLIBCXX17_INLINE constexpr match_flag_type match_continuous = _S_continuous;
316
317 /**
318 * `--first` is a valid iterator position. When this flag is set then the
319 * flags `match_not_bol` and `match_not_bow` are ignored by the algorithms
320 * `regex_match`, `regex_search`, and `regex_replace`, and by the iterators
321 * `regex_iterator` and `regex_token_iterator`.
322 */
323 _GLIBCXX17_INLINE constexpr match_flag_type match_prev_avail = _S_prev_avail;
324
325 /**
326 * When a regular expression match is to be replaced by a new string, the
327 * new string is constructed using the rules used by the ECMAScript replace
328 * function in ECMA- 262 [Ecma International, ECMAScript Language
329 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
330 * String.prototype.replace. In addition, during search and replace
331 * operations all non-overlapping occurrences of the regular expression
332 * are located and replaced, and sections of the input that did not match
333 * the expression are copied unchanged to the output string.
334 *
335 * Format strings (from ECMA-262 [15.5.4.11]):
336 * @li $$ The dollar-sign itself ($)
337 * @li $& The matched substring.
338 * @li $\` The portion of the string that precedes the matched substring.
339 * This would be match_results::prefix().
340 * @li $' The portion of the string that follows the matched substring.
341 * This would be match_results::suffix().
342 * @li $n The nth capture, where n is a positive integer less than 100.
343 * If `n <= match_results::size()` and the nth capture is undefined,
344 * use the empty string instead. If `n > match_results::size()`,
345 * the result is implementation-defined.
346 */
347 _GLIBCXX17_INLINE constexpr match_flag_type format_default = _S_default;
348
349 /**
350 * When a regular expression match is to be replaced by a new string, the
351 * new string is constructed using the rules used by the POSIX sed utility
352 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
353 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
354 */
355 _GLIBCXX17_INLINE constexpr match_flag_type format_sed = _S_sed;
356
357 /**
358 * During a search and replace operation, sections of the character
359 * container sequence being searched that do not match the regular
360 * expression shall not be copied to the output string.
361 */
362 _GLIBCXX17_INLINE constexpr match_flag_type format_no_copy = _S_no_copy;
363
364 /**
365 * When specified during a search and replace operation, only the first
366 * occurrence of the regular expression shall be replaced.
367 */
368 _GLIBCXX17_INLINE constexpr match_flag_type format_first_only = _S_first_only;
369
370 [[__nodiscard__]]
371 constexpr match_flag_type
372 operator&(match_flag_type __a, match_flag_type __b) noexcept
373 {
374 return (match_flag_type)(static_cast<unsigned int>(__a)
375 & static_cast<unsigned int>(__b));
376 }
377
378 [[__nodiscard__]]
379 constexpr match_flag_type
380 operator|(match_flag_type __a, match_flag_type __b) noexcept
381 {
382 return (match_flag_type)(static_cast<unsigned int>(__a)
383 | static_cast<unsigned int>(__b));
384 }
385
386 [[__nodiscard__]]
387 constexpr match_flag_type
388 operator^(match_flag_type __a, match_flag_type __b) noexcept
389 {
390 return (match_flag_type)(static_cast<unsigned int>(__a)
391 ^ static_cast<unsigned int>(__b));
392 }
393
394 [[__nodiscard__]]
395 constexpr match_flag_type
396 operator~(match_flag_type __a) noexcept
397 { return (match_flag_type)(~static_cast<unsigned int>(__a)); }
398
399 _GLIBCXX14_CONSTEXPR
400 inline match_flag_type&
401 operator&=(match_flag_type& __a, match_flag_type __b) noexcept
402 { return __a = __a & __b; }
403
404 _GLIBCXX14_CONSTEXPR
405 inline match_flag_type&
406 operator|=(match_flag_type& __a, match_flag_type __b) noexcept
407 { return __a = __a | __b; }
408
409 _GLIBCXX14_CONSTEXPR
410 inline match_flag_type&
411 operator^=(match_flag_type& __a, match_flag_type __b) noexcept
412 { return __a = __a ^ __b; }
413
414 ///@}
415} // namespace regex_constants
416/// @} group regex
417
418_GLIBCXX_END_NAMESPACE_VERSION
419} // namespace std
420
std
ISO C++ entities toplevel namespace is std.
std::regex_constants
ISO C++ 2011 namespace for options and flags used with std::regex.
std::regex_constants::__polynomial
constexpr syntax_option_type __polynomial
Definition regex_constants.h:187
std::regex_constants::collate
constexpr syntax_option_type collate
Definition regex_constants.h:110
std::regex_constants::operator^=
constexpr syntax_option_type & operator^=(syntax_option_type &__a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:230
std::regex_constants::match_not_bow
constexpr match_flag_type match_not_bow
Definition regex_constants.h:293
std::regex_constants::operator&=
constexpr syntax_option_type & operator&=(syntax_option_type &__a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:220
std::regex_constants::match_not_bol
constexpr match_flag_type match_not_bol
Definition regex_constants.h:280
std::regex_constants::ECMAScript
constexpr syntax_option_type ECMAScript
Definition regex_constants.h:120
std::regex_constants::match_any
constexpr match_flag_type match_any
Definition regex_constants.h:305
std::regex_constants::egrep
constexpr syntax_option_type egrep
Definition regex_constants.h:163
std::regex_constants::syntax_option_type
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:70
std::regex_constants::operator&
constexpr syntax_option_type operator&(syntax_option_type __a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:191
std::regex_constants::multiline
constexpr syntax_option_type multiline
Definition regex_constants.h:175
std::regex_constants::match_default
constexpr match_flag_type match_default
Definition regex_constants.h:273
std::regex_constants::format_first_only
constexpr match_flag_type format_first_only
Definition regex_constants.h:368
std::regex_constants::awk
constexpr syntax_option_type awk
Definition regex_constants.h:147
std::regex_constants::__multiline
constexpr syntax_option_type __multiline
Extension: Equivalent to regex_constants::multiline for C++11 and C++14.
Definition regex_constants.h:179
std::regex_constants::match_continuous
constexpr match_flag_type match_continuous
Definition regex_constants.h:315
std::regex_constants::extended
constexpr syntax_option_type extended
Definition regex_constants.h:137
std::regex_constants::operator|
constexpr syntax_option_type operator|(syntax_option_type __a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:199
std::regex_constants::operator^
constexpr syntax_option_type operator^(syntax_option_type __a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:207
std::regex_constants::basic
constexpr syntax_option_type basic
Definition regex_constants.h:129
std::regex_constants::match_not_eol
constexpr match_flag_type match_not_eol
Definition regex_constants.h:287
std::regex_constants::match_flag_type
match_flag_type
This is a bitmask type indicating regex matching rules.
Definition regex_constants.h:254
std::regex_constants::icase
constexpr syntax_option_type icase
Definition regex_constants.h:89
std::regex_constants::operator~
constexpr syntax_option_type operator~(syntax_option_type __a) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:215
std::regex_constants::optimize
constexpr syntax_option_type optimize
Definition regex_constants.h:104
std::regex_constants::format_default
constexpr match_flag_type format_default
Definition regex_constants.h:347
std::regex_constants::nosubs
constexpr syntax_option_type nosubs
Definition regex_constants.h:96
std::regex_constants::match_prev_avail
constexpr match_flag_type match_prev_avail
Definition regex_constants.h:323
std::regex_constants::format_sed
constexpr match_flag_type format_sed
Definition regex_constants.h:355
std::regex_constants::operator|=
constexpr syntax_option_type & operator|=(syntax_option_type &__a, syntax_option_type __b) noexcept
This is a bitmask type indicating how to interpret the regex.
Definition regex_constants.h:225
std::regex_constants::match_not_eow
constexpr match_flag_type match_not_eow
Definition regex_constants.h:299
std::regex_constants::match_not_null
constexpr match_flag_type match_not_null
Definition regex_constants.h:310
std::regex_constants::format_no_copy
constexpr match_flag_type format_no_copy
Definition regex_constants.h:362
std::regex_constants::grep
constexpr syntax_option_type grep
Definition regex_constants.h:155