File: overview_resyntax.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (535 lines) | stat: -rw-r--r-- 39,362 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Regular Expressions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Regular Expressions </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_resyntax_differentflavors">Different Flavors of Regular Expressions</a></li>
<li class="level1"><a href="#overview_resyntax_syntax">Regular Expression Syntax</a></li>
<li class="level1"><a href="#overview_resyntax_bracket">Bracket Expressions</a></li>
<li class="level1"><a href="#overview_resyntax_escapes">Escapes</a></li>
<li class="level1"><a href="#overview_resyntax_metasyntax">Metasyntax</a></li>
<li class="level1"><a href="#overview_resyntax_matching">Matching</a></li>
<li class="level1"><a href="#overview_resyntax_limits">Limits and Compatibility</a></li>
<li class="level1"><a href="#overview_resyntax_bre">Basic Regular Expressions</a></li>
<li class="level1"><a href="#overview_resyntax_characters">Regular Expression Character Names</a></li>
</ul>
</div>
<div class="textblock"><p>A <em>regular expression</em> describes strings of characters.</p>
<p>It's a pattern that matches certain strings and doesn't match others.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_reg_ex.html" title="wxRegEx represents a regular expression.">wxRegEx</a></dd></dl>
<h1><a class="anchor" id="overview_resyntax_differentflavors"></a>
Different Flavors of Regular Expressions</h1>
<p>Regular expressions (RE), as defined by POSIX, come in two flavors: <em>extended regular expressions</em> (ERE) and <em>basic regular expressions</em> (BRE). EREs are roughly those of the traditional <em>egrep</em>, while BREs are roughly those of the traditional <em>ed</em>. This implementation adds a third flavor: <em>advanced regular expressions</em> (ARE), basically EREs with some significant extensions.</p>
<p>This manual page primarily describes AREs. BREs mostly exist for backward compatibility in some old programs. POSIX EREs are almost an exact subset of AREs. Features of AREs that are not present in EREs will be indicated.</p>
<h1><a class="anchor" id="overview_resyntax_syntax"></a>
Regular Expression Syntax</h1>
<p>These regular expressions are implemented using the package written by Henry Spencer, based on the 1003.2 spec and some (not quite all) of the Perl5 extensions (thanks, Henry!). Much of the description of regular expressions below is copied verbatim from his manual entry.</p>
<p>An ARE is one or more <em>branches</em>, separated by "|", matching anything that matches any of the branches.</p>
<p>A branch is zero or more <em>constraints</em> or <em>quantified</em> atoms, concatenated. It matches a match for the first, followed by a match for the second, etc; an empty branch matches the empty string.</p>
<p>A quantified atom is an <em>atom</em> possibly followed by a single <em>quantifier</em>. Without a quantifier, it matches a match for the atom. The quantifiers, and what a so-quantified atom matches, are:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>*</code>  </td><td>A sequence of 0 or more matches of the atom.  </td></tr>
<tr>
<td><code>+</code>  </td><td>A sequence of 1 or more matches of the atom.  </td></tr>
<tr>
<td><code>?</code>  </td><td>A sequence of 0 or 1 matches of the atom.  </td></tr>
<tr>
<td><code>{m}</code>  </td><td>A sequence of exactly <em>m</em> matches of the atom.  </td></tr>
<tr>
<td><code>{m,}</code>  </td><td>A sequence of <em>m</em> or more matches of the atom.  </td></tr>
<tr>
<td><code>{m,n}</code>  </td><td>A sequence of <em>m</em> through <em>n</em> (inclusive) matches of the atom; <em>m</em> may not exceed <em>n</em>.  </td></tr>
<tr>
<td><code>*? +? ?? {m}? {m,}? {m,n}?</code>  </td><td><em>Non-greedy</em> quantifiers, which match the same possibilities, but prefer the smallest number rather than the largest number of matches (see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a>).  </td></tr>
</table>
<p>The forms using <b>{</b> and <b>}</b> are known as <em>bounds</em>. The numbers <em>m</em> and <em>n</em> are unsigned decimal integers with permissible values from 0 to 255 inclusive. An atom is one of:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>(re)</code>  </td><td>Where <em>re</em> is any regular expression, matches for <em>re</em>, with the match captured for possible reporting.  </td></tr>
<tr>
<td><code>(?:re)</code>  </td><td>As previous, but does no reporting (a "non-capturing" set of parentheses).  </td></tr>
<tr>
<td><code>()</code>  </td><td>Matches an empty string, captured for possible reporting.  </td></tr>
<tr>
<td><code>(?:)</code>  </td><td>Matches an empty string, without reporting.  </td></tr>
<tr>
<td><code>[chars]</code>  </td><td>A <em>bracket expression</em>, matching any one of the <em>chars</em> (see <a class="el" href="overview_resyntax.html#overview_resyntax_bracket">Bracket Expressions</a> for more details).  </td></tr>
<tr>
<td><code>.</code>  </td><td>Matches any single character.  </td></tr>
<tr>
<td><code>\k</code>  </td><td>Where <em>k</em> is a non-alphanumeric character, matches that character taken as an ordinary character, e.g. \\ matches a backslash character.  </td></tr>
<tr>
<td><code>\c</code>  </td><td>Where <em>c</em> is alphanumeric (possibly followed by other characters), an <em>escape</em> (AREs only), see <a class="el" href="overview_resyntax.html#overview_resyntax_escapes">Escapes</a> below.  </td></tr>
<tr>
<td><code>{</code>  </td><td>When followed by a character other than a digit, matches the left-brace character "{"; when followed by a digit, it is the beginning of a <em>bound</em> (see above).  </td></tr>
<tr>
<td><code>x</code>  </td><td>Where <em>x</em> is a single character with no other significance, matches that character.  </td></tr>
</table>
<p>A <em>constraint</em> matches an empty string when specific conditions are met. A constraint may not be followed by a quantifier. The simple constraints are as follows; some more constraints are described later, under <a class="el" href="overview_resyntax.html#overview_resyntax_escapes">Escapes</a>.</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>^</code>  </td><td>Matches at the beginning of a line.  </td></tr>
<tr>
<td><code>$</code>  </td><td>Matches at the end of a line.  </td></tr>
<tr>
<td><code>(?=re)</code>  </td><td><em>Positive</em> lookahead (AREs only), matches at any point where a substring matching <em>re</em> begins.  </td></tr>
<tr>
<td><code>(?!re)</code>  </td><td><em>Negative</em> lookahead (AREs only), matches at any point where no substring matching <em>re</em> begins.  </td></tr>
</table>
<p>The lookahead constraints may not contain back references (see later), and all parentheses within them are considered non-capturing. A RE may not end with "\".</p>
<h1><a class="anchor" id="overview_resyntax_bracket"></a>
Bracket Expressions</h1>
<p>A <em>bracket expression</em> is a list of characters enclosed in <code>[]</code>. It normally matches any single character from the list (but see below). If the list begins with <code>^</code>, it matches any single character (but see below) <em>not</em> from the rest of the list.</p>
<p>If two characters in the list are separated by <code>-</code>, this is shorthand for the full <em>range</em> of characters between those two (inclusive) in the collating sequence, e.g. <code>[0-9]</code> in ASCII matches any decimal digit. Two ranges may not share an endpoint, so e.g. <code>a-c-e</code> is illegal. Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them.</p>
<p>To include a literal <code>]</code> or <code>-</code> in the list, the simplest method is to enclose it in <code>[.</code> and <code>.]</code> to make it a collating element (see below). Alternatively, make it the first character (following a possible <code>^</code>), or (AREs only) precede it with <code>\</code>. Alternatively, for <code>-</code>, make it the last character, or the second endpoint of a range. To use a literal <code>-</code> as the first endpoint of a range, make it a collating element or (AREs only) precede it with <code>\</code>. With the exception of these, some combinations using <code>[</code> (see next paragraphs), and escapes, all other special characters lose their special significance within a bracket expression.</p>
<p>Within a bracket expression, a collating element (a character, a multi-character sequence that collates as if it were a single character, or a collating-sequence name for either) enclosed in <code>[.</code> and <code>.]</code> stands for the sequence of characters of that collating element.</p>
<p><em>wxWidgets:</em> Currently no multi-character collating elements are defined. So in <code>[.X.]</code>, <code>X</code> can either be a single character literal or the name of a character. For example, the following are both identical: <code>[[.0.]-[.9.]]</code> and <code>[[.zero.]-[.nine.]]</code> and mean the same as <code>[0-9]</code>. See <a class="el" href="overview_resyntax.html#overview_resyntax_characters">Regular Expression Character Names</a>.</p>
<p>Within a bracket expression, a collating element enclosed in <code>[=</code> and <code>=]</code> is an equivalence class, standing for the sequences of characters of all collating elements equivalent to that one, including itself. An equivalence class may not be an endpoint of a range.</p>
<p><em>wxWidgets:</em> Currently no equivalence classes are defined, so <code>[=X=]</code> stands for just the single character <code>X</code>. <code>X</code> can either be a single character literal or the name of a character, see <a class="el" href="overview_resyntax.html#overview_resyntax_characters">Regular Expression Character Names</a>.</p>
<p>Within a bracket expression, the name of a <em>character</em> class enclosed in <code>[:</code> and <code>:]</code> stands for the list of all characters (not all collating elements!) belonging to that class. Standard character classes are:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>alpha</code>  </td><td>A letter.  </td></tr>
<tr>
<td><code>upper</code>  </td><td>An upper-case letter.  </td></tr>
<tr>
<td><code>lower</code>  </td><td>A lower-case letter.  </td></tr>
<tr>
<td><code>digit</code>  </td><td>A decimal digit.  </td></tr>
<tr>
<td><code>xdigit</code>  </td><td>A hexadecimal digit.  </td></tr>
<tr>
<td><code>alnum</code>  </td><td>An alphanumeric (letter or digit).  </td></tr>
<tr>
<td><code>print</code>  </td><td>An alphanumeric (same as alnum).  </td></tr>
<tr>
<td><code>blank</code>  </td><td>A space or tab character.  </td></tr>
<tr>
<td><code>space</code>  </td><td>A character producing white space in displayed text.  </td></tr>
<tr>
<td><code>punct</code>  </td><td>A punctuation character.  </td></tr>
<tr>
<td><code>graph</code>  </td><td>A character with a visible representation.  </td></tr>
<tr>
<td><code>cntrl</code>  </td><td>A control character.  </td></tr>
</table>
<p>A character class may not be used as an endpoint of a range.</p>
<p><em>wxWidgets:</em> In a non-Unicode build, these character classifications depend on the current locale, and correspond to the values return by the ANSI C "is" functions: <code>isalpha</code>, <code>isupper</code>, etc. In Unicode mode they are based on Unicode classifications, and are not affected by the current locale.</p>
<p>There are two special cases of bracket expressions: the bracket expressions <code>[[:&lt;:]]</code> and <code>[[:&gt;:]]</code> are constraints, matching empty strings at the beginning and end of a word respectively. A word is defined as a sequence of word characters that is neither preceded nor followed by word characters. A word character is an <em>alnum</em> character or an underscore (_). These special bracket expressions are deprecated; users of AREs should use constraint escapes instead (see escapes below).</p>
<h1><a class="anchor" id="overview_resyntax_escapes"></a>
Escapes</h1>
<p>Escapes (AREs only), which begin with a <code>\</code> followed by an alphanumeric character, come in several varieties: character entry, class shorthands, constraint escapes, and back references. A <code>\</code> followed by an alphanumeric character but not constituting a valid escape is illegal in AREs. In EREs, there are no escapes: outside a bracket expression, a <code>\</code> followed by an alphanumeric character merely stands for that character as an ordinary character, and inside a bracket expression, <code>\</code> is an ordinary character. (The latter is the one actual incompatibility between EREs and AREs.)</p>
<p>Character-entry escapes (AREs only) exist to make it easier to specify non-printing and otherwise inconvenient characters in REs:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>\a</code>  </td><td>Alert (bell) character, as in C.  </td></tr>
<tr>
<td><code>\b</code>  </td><td>Backspace, as in C.  </td></tr>
<tr>
<td><code>\B</code>  </td><td>Synonym for <code>\</code> to help reduce backslash doubling in some applications where there are multiple levels of backslash processing.  </td></tr>
<tr>
<td><code>\cX</code>  </td><td>The character whose low-order 5 bits are the same as those of <em>X</em>, and whose other bits are all zero, where <em>X</em> is any character.  </td></tr>
<tr>
<td><code>\e</code>  </td><td>The character whose collating-sequence name is <code>ESC</code>, or failing that, the character with octal value 033.  </td></tr>
<tr>
<td><code>\f</code>  </td><td>Formfeed, as in C.  </td></tr>
<tr>
<td><code>\n</code>  </td><td>Newline, as in C.  </td></tr>
<tr>
<td><code>\r</code>  </td><td>Carriage return, as in C.  </td></tr>
<tr>
<td><code>\t</code>  </td><td>Horizontal tab, as in C.  </td></tr>
<tr>
<td><code>\uwxyz</code>  </td><td>The Unicode character <code>U+wxyz</code> in the local byte ordering, where <em>wxyz</em> is exactly four hexadecimal digits.  </td></tr>
<tr>
<td><code>\Ustuvwxyz</code>  </td><td>Reserved for a somewhat-hypothetical Unicode extension to 32 bits, where <em>stuvwxyz</em> is exactly eight hexadecimal digits.  </td></tr>
<tr>
<td><code>\v</code>  </td><td>Vertical tab, as in C are all available.  </td></tr>
<tr>
<td><code>\xhhh</code>  </td><td>The single character whose hexadecimal value is <em>0xhhh</em>, where <em>hhh</em> is any sequence of hexadecimal digits.  </td></tr>
<tr>
<td><code>\0</code>  </td><td>The character whose value is 0.  </td></tr>
<tr>
<td><code>\xy</code>  </td><td>The character whose octal value is <em>0xy</em>, where <em>xy</em> is exactly two octal digits, and is not a <em>back reference</em> (see below).  </td></tr>
<tr>
<td><code>\xyz</code>  </td><td>The character whose octal value is <em>0xyz</em>, where <em>xyz</em> is exactly three octal digits, and is not a <em>back reference</em> (see below).  </td></tr>
</table>
<p>Hexadecimal digits are 0-9, a-f, and A-F. Octal digits are 0-7.</p>
<p>The character-entry escapes are always taken as ordinary characters. For example, <code>\135</code> is <code>]</code> in ASCII, but <code>\135</code> does not terminate a bracket expression. Beware, however, that some applications (e.g., C compilers) interpret such sequences themselves before the regular-expression package gets to see them, which may require doubling (quadrupling, etc.) the '<code>\</code>'.</p>
<p>Class-shorthand escapes (AREs only) provide shorthands for certain commonly-used character classes:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>\d</code>  </td><td><code>[[:digit:]]</code>  </td></tr>
<tr>
<td><code>\s</code>  </td><td><code>[[:space:]]</code>  </td></tr>
<tr>
<td><code>\w</code>  </td><td><code>[[:alnum:]_]</code> (note underscore)  </td></tr>
<tr>
<td><code>\D</code>  </td><td><code>[^[:digit:]]</code>  </td></tr>
<tr>
<td><code>\S</code>  </td><td><code>[^[:space:]]</code>  </td></tr>
<tr>
<td><code>\W</code>  </td><td><code>[^[:alnum:]_]</code> (note underscore)  </td></tr>
</table>
<p>Within bracket expressions, <code>\d</code>, <code>\s</code>, and <code>\w</code> lose their outer brackets, and <code>\D</code>, <code>\S</code>, <code>\W</code> are illegal. So, for example, <code>[a-c\d]</code> is equivalent to <code>[a-c[:digit:]]</code>. Also, <code>[a-c\D]</code>, which is equivalent to <code>[a-c^[:digit:]]</code>, is illegal.</p>
<p>A constraint escape (AREs only) is a constraint, matching the empty string if specific conditions are met, written as an escape:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>\A</code>  </td><td>Matches only at the beginning of the string, see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a> for how this differs from <code>^</code>.  </td></tr>
<tr>
<td><code>\m</code>  </td><td>Matches only at the beginning of a word.  </td></tr>
<tr>
<td><code>\M</code>  </td><td>Matches only at the end of a word.  </td></tr>
<tr>
<td><code>\y</code>  </td><td>Matches only at the beginning or end of a word.  </td></tr>
<tr>
<td><code>\Y</code>  </td><td>Matches only at a point that is not the beginning or end of a word.  </td></tr>
<tr>
<td><code>\Z</code>  </td><td>Matches only at the end of the string, see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a> for how this differs from <code>$</code>.  </td></tr>
<tr>
<td><code>\m</code>  </td><td>A <em>back reference</em>, where <em>m</em> is a non-zero digit. See below.  </td></tr>
<tr>
<td><code>\mnn</code>  </td><td>A <em>back reference</em>, where <em>m</em> is a nonzero digit, and <em>nn</em> is some more digits, and the decimal value <em>mnn</em> is not greater than the number of closing capturing parentheses seen so far. See below.  </td></tr>
</table>
<p>A word is defined as in the specification of <code>[[:&lt;:]]</code> and <code>[[:&gt;:]]</code> above. Constraint escapes are illegal within bracket expressions.</p>
<p>A back reference (AREs only) matches the same string matched by the parenthesized subexpression specified by the number. For example, "([bc])\1" matches "bb" or "cc" but not "bc". The subexpression must entirely precede the back reference in the RE.Subexpressions are numbered in the order of their leading parentheses. Non-capturing parentheses do not define subexpressions.</p>
<p>There is an inherent historical ambiguity between octal character-entry escapes and back references, which is resolved by heuristics, as hinted at above. A leading zero always indicates an octal escape. A single non-zero digit, not followed by another digit, is always taken as a back reference. A multi-digit sequence not starting with a zero is taken as a back reference if it comes after a suitable subexpression (i.e. the number is in the legal range for a back reference), and otherwise is taken as octal.</p>
<h1><a class="anchor" id="overview_resyntax_metasyntax"></a>
Metasyntax</h1>
<p>In addition to the main syntax described above, there are some special forms and miscellaneous syntactic facilities available.</p>
<p>Normally the flavor of RE being used is specified by application-dependent means. However, this can be overridden by a <em>director</em>. If an RE of any flavor begins with <code>***:</code>, the rest of the RE is an ARE. If an RE of any flavor begins with <code>***=</code>, the rest of the RE is taken to be a literal string, with all characters considered ordinary characters.</p>
<p>An ARE may begin with <em>embedded options</em>: a sequence <code>(?xyz)</code> (where <em>xyz</em> is one or more alphabetic characters) specifies options affecting the rest of the RE. These supplement, and can override, any options specified by the application. The available option letters are:</p>
<table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>b</code>  </td><td>Rest of RE is a BRE.  </td></tr>
<tr>
<td><code>c</code>  </td><td>Case-sensitive matching (usual default).  </td></tr>
<tr>
<td><code>e</code>  </td><td>Rest of RE is an ERE.  </td></tr>
<tr>
<td><code>i</code>  </td><td>Case-insensitive matching (see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a>, below).  </td></tr>
<tr>
<td><code>m</code>  </td><td>Historical synonym for <em>n</em>.  </td></tr>
<tr>
<td><code>n</code>  </td><td>Newline-sensitive matching (see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a>, below).  </td></tr>
<tr>
<td><code>p</code>  </td><td>Partial newline-sensitive matching (see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a>, below).  </td></tr>
<tr>
<td><code>q</code>  </td><td>Rest of RE is a literal ("quoted") string, all ordinary characters.  </td></tr>
<tr>
<td><code>s</code>  </td><td>Non-newline-sensitive matching (usual default).  </td></tr>
<tr>
<td><code>t</code>  </td><td>Tight syntax (usual default; see below).  </td></tr>
<tr>
<td><code>w</code>  </td><td>Inverse partial newline-sensitive ("weird") matching (see <a class="el" href="overview_resyntax.html#overview_resyntax_matching">Matching</a>, below).  </td></tr>
<tr>
<td><code>x</code>  </td><td>Expanded syntax (see below).  </td></tr>
</table>
<p>Embedded options take effect at the <code>)</code> terminating the sequence. They are available only at the start of an ARE, and may not be used later within it.</p>
<p>In addition to the usual (<em>tight</em>) RE syntax, in which all characters are significant, there is an <em>expanded</em> syntax, available in AREs with the embedded x option. In the expanded syntax, white-space characters are ignored and all characters between a <code>#</code> and the following newline (or the end of the RE) are ignored, permitting paragraphing and commenting a complex RE. There are three exceptions to that basic rule:</p>
<ul>
<li>A white-space character or <code>#</code> preceded by <code>\</code> is retained. </li>
<li>White space or <code>#</code> within a bracket expression is retained. </li>
<li>White space and comments are illegal within multi-character symbols like the ARE <code>(?:</code> or the BRE <code>(</code>.</li>
</ul>
<p>Expanded-syntax white-space characters are blank, tab, newline, and any character that belongs to the <em>space</em> character class.</p>
<p>Finally, in an ARE, outside bracket expressions, the sequence <code>(?#ttt)</code> (where <em>ttt</em> is any text not containing a <code>)</code>) is a comment, completely ignored. Again, this is not allowed between the characters of multi-character symbols like <code>(?:</code>. Such comments are more a historical artifact than a useful facility, and their use is deprecated; use the expanded syntax instead.</p>
<p><em>None</em> of these metasyntax extensions is available if the application (or an initial <code>***=</code> director) has specified that the user's input be treated as a literal string rather than as an RE.</p>
<h1><a class="anchor" id="overview_resyntax_matching"></a>
Matching</h1>
<p>In the event that an RE could match more than one substring of a given string, the RE matches the one starting earliest in the string. If the RE could match more than one substring starting at that point, the choice is determined by it's <em>preference:</em> either the longest substring, or the shortest.</p>
<p>Most atoms, and all constraints, have no preference. A parenthesized RE has the same preference (possibly none) as the RE. A quantified atom with quantifier <code>{m}</code> or <code>{m}?</code> has the same preference (possibly none) as the atom itself. A quantified atom with other normal quantifiers (including <code>{m,n}</code> with <em>m</em> equal to <em>n</em>) prefers longest match. A quantified atom with other non-greedy quantifiers (including <code>{m,n}?</code> with <em>m</em> equal to <em>n</em>) prefers shortest match. A branch has the same preference as the first quantified atom in it which has a preference. An RE consisting of two or more branches connected by the <code></code>| operator prefers longest match.</p>
<p>Subject to the constraints imposed by the rules for matching the whole RE, subexpressions also match the longest or shortest possible substrings, based on their preferences, with subexpressions starting earlier in the RE taking priority over ones starting later. Note that outer subexpressions thus take priority over their component subexpressions.</p>
<p>Note that the quantifiers <code>{1,1}</code> and <code>{1,1}?</code> can be used to force longest and shortest preference, respectively, on a subexpression or a whole RE.</p>
<p>Match lengths are measured in characters, not collating elements. An empty string is considered longer than no match at all. For example, <code>bb*</code> matches the three middle characters of "abbbc", <code>(week|wee)(night|knights)</code> matches all ten characters of "weeknights", when <code>(.*).*</code> is matched against "abc" the parenthesized subexpression matches all three characters, and when <code>(a*)*</code> is matched against "bc" both the whole RE and the parenthesized subexpression match an empty string.</p>
<p>If case-independent matching is specified, the effect is much as if all case distinctions had vanished from the alphabet. When an alphabetic that exists in multiple cases appears as an ordinary character outside a bracket expression, it is effectively transformed into a bracket expression containing both cases, so that <code>x</code> becomes <code></code>[xX]. When it appears inside a bracket expression, all case counterparts of it are added to the bracket expression, so that <code></code>[x] becomes <code></code>[xX] and <code></code>[^x] becomes <code></code>[^xX].</p>
<p>If newline-sensitive matching is specified, "." and bracket expressions using "^" will never match the newline character (so that matches will never cross newlines unless the RE explicitly arranges it) and "^" and "$" will match the empty string after and before a newline respectively, in addition to matching at beginning and end of string respectively. ARE <code>\A</code> and <code>\Z</code> continue to match beginning or end of string <em>only</em>.</p>
<p>If partial newline-sensitive matching is specified, this affects "." and bracket expressions as with newline-sensitive matching, but not "^" and "$".</p>
<p>If inverse partial newline-sensitive matching is specified, this affects "^" and "$" as with newline-sensitive matching, but not "." and bracket expressions. This isn't very useful but is provided for symmetry.</p>
<h1><a class="anchor" id="overview_resyntax_limits"></a>
Limits and Compatibility</h1>
<p>No particular limit is imposed on the length of REs. Programs intended to be highly portable should not employ REs longer than 256 bytes, as a POSIX-compliant implementation can refuse to accept such REs.</p>
<p>The only feature of AREs that is actually incompatible with POSIX EREs is that <code>\</code> does not lose its special significance inside bracket expressions. All other ARE features use syntax which is illegal or has undefined or unspecified effects in POSIX EREs; the <code>***</code> syntax of directors likewise is outside the POSIX syntax for both BREs and EREs.</p>
<p>Many of the ARE extensions are borrowed from Perl, but some have been changed to clean them up, and a few Perl extensions are not present. Incompatibilities of note include <code>\b</code>, <code>\B</code>, the lack of special treatment for a trailing newline, the addition of complemented bracket expressions to the things affected by newline-sensitive matching, the restrictions on parentheses and back references in lookahead constraints, and the longest/shortest-match (rather than first-match) matching semantics.</p>
<p>The matching rules for REs containing both normal and non-greedy quantifiers have changed since early beta-test versions of this package. The new rules are much simpler and cleaner, but don't work as hard at guessing the user's real intentions.</p>
<p>Henry Spencer's original 1986 <em>regexp</em> package, still in widespread use, implemented an early version of today's EREs. There are four incompatibilities between <em>regexp's</em> near-EREs (RREs for short) and AREs. In roughly increasing order of significance:</p>
<ul>
<li>In AREs, <code>\</code> followed by an alphanumeric character is either an escape or an error, while in RREs, it was just another way of writing the alphanumeric. This should not be a problem because there was no reason to write such a sequence in RREs. </li>
<li><code>{</code> followed by a digit in an ARE is the beginning of a bound, while in RREs, <code>{</code> was always an ordinary character. Such sequences should be rare, and will often result in an error because following characters will not look like a valid bound. </li>
<li>In AREs, <code>\</code> remains a special character within <code></code>[], so a literal <code>\</code> within <code></code>[] must be written as <code>\\</code>. <code>\\</code> also gives a literal <code>\</code> within <code></code>[] in RREs, but only truly paranoid programmers routinely doubled the backslash. </li>
<li>AREs report the longest/shortest match for the RE, rather than the first found in a specified search order. This may affect some RREs which were written in the expectation that the first match would be reported. The careful crafting of RREs to optimize the search order for fast matching is obsolete (AREs examine all possible matches in parallel, and their performance is largely insensitive to their complexity) but cases where the search order was exploited to deliberately find a match which was <em>not</em> the longest/shortest will need rewriting.</li>
</ul>
<h1><a class="anchor" id="overview_resyntax_bre"></a>
Basic Regular Expressions</h1>
<p>BREs differ from EREs in several respects. <code></code>|, <code>+</code>, and <code></code>? are ordinary characters and there is no equivalent for their functionality. The delimiters for bounds are <code>\{</code> and <code>\}</code>, with <code>{</code> and <code>}</code> by themselves ordinary characters. The parentheses for nested subexpressions are <code>@</code>( and <code>@</code>), with <code></code>( and <code></code>) by themselves ordinary characters. <code>^</code> is an ordinary character except at the beginning of the RE or the beginning of a parenthesized subexpression, <code>$</code> is an ordinary character except at the end of the RE or the end of a parenthesized subexpression, and <code>*</code> is an ordinary character if it appears at the beginning of the RE or the beginning of a parenthesized subexpression (after a possible leading <code>^</code>). Finally, single-digit back references are available, and <code>\&lt;</code> and <code>\&gt;</code> are synonyms for <code>[[:&lt;:]]</code> and <code>[[:&gt;:]]</code> respectively; no other escapes are available.</p>
<h1><a class="anchor" id="overview_resyntax_characters"></a>
Regular Expression Character Names</h1>
<p>Note that the character names are case sensitive.</p>
<center><table  class="doctable" border="0" cellspacing="5" cellpadding="4">
<tr>
<td><table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>NUL</code>  </td><td>\0  </td></tr>
<tr>
<td><code>SOH</code>  </td><td>\001  </td></tr>
<tr>
<td><code>STX</code>  </td><td>\002  </td></tr>
<tr>
<td><code>ETX</code>  </td><td>\003  </td></tr>
<tr>
<td><code>EOT</code>  </td><td>\004  </td></tr>
<tr>
<td><code>ENQ</code>  </td><td>\005  </td></tr>
<tr>
<td><code>ACK</code>  </td><td>\006  </td></tr>
<tr>
<td><code>BEL</code>  </td><td>\007  </td></tr>
<tr>
<td><code>alert</code>  </td><td>\007  </td></tr>
<tr>
<td><code>BS</code>  </td><td>\010  </td></tr>
<tr>
<td><code>backspace</code>  </td><td>\b  </td></tr>
<tr>
<td><code>HT</code>  </td><td>\011  </td></tr>
<tr>
<td><code>tab</code>  </td><td>\t  </td></tr>
<tr>
<td><code>LF</code>  </td><td>\012  </td></tr>
<tr>
<td><code>newline</code>  </td><td>\n  </td></tr>
<tr>
<td><code>VT</code>  </td><td>\013  </td></tr>
<tr>
<td><code>vertical-tab</code>  </td><td>\v  </td></tr>
<tr>
<td><code>FF</code>  </td><td>\014  </td></tr>
<tr>
<td><code>form-feed</code>  </td><td>\f  </td></tr>
</table>
<p class="endtd"></p>
</td><td><table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>CR</code>  </td><td>\015  </td></tr>
<tr>
<td><code>carriage-return</code>  </td><td>\r  </td></tr>
<tr>
<td><code>SO</code>  </td><td>\016  </td></tr>
<tr>
<td><code>SI</code>  </td><td>\017  </td></tr>
<tr>
<td><code>DLE</code>  </td><td>\020  </td></tr>
<tr>
<td><code>DC1</code>  </td><td>\021  </td></tr>
<tr>
<td><code>DC2</code>  </td><td>\022  </td></tr>
<tr>
<td><code>DC3</code>  </td><td>\023  </td></tr>
<tr>
<td><code>DC4</code>  </td><td>\024  </td></tr>
<tr>
<td><code>NAK</code>  </td><td>\025  </td></tr>
<tr>
<td><code>SYN</code>  </td><td>\026  </td></tr>
<tr>
<td><code>ETB</code>  </td><td>\027  </td></tr>
<tr>
<td><code>CAN</code>  </td><td>\030  </td></tr>
<tr>
<td><code>EM</code>  </td><td>\031  </td></tr>
<tr>
<td><code>SUB</code>  </td><td>\032  </td></tr>
<tr>
<td><code>ESC</code>  </td><td>\033  </td></tr>
<tr>
<td><code>IS4</code>  </td><td>\034  </td></tr>
<tr>
<td><code>FS</code>  </td><td>\034  </td></tr>
<tr>
<td><code>IS3</code>  </td><td>\035  </td></tr>
</table>
<p class="endtd"></p>
</td><td><table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>GS</code>  </td><td>\035  </td></tr>
<tr>
<td><code>IS2</code>  </td><td>\036  </td></tr>
<tr>
<td><code>RS</code>  </td><td>\036  </td></tr>
<tr>
<td><code>IS1</code>  </td><td>\037  </td></tr>
<tr>
<td><code>US</code>  </td><td>\037  </td></tr>
<tr>
<td><code>space</code>  </td><td>" " (space)  </td></tr>
<tr>
<td><code>exclamation-mark</code>  </td><td>!  </td></tr>
<tr>
<td><code>quotation-mark</code>  </td><td>"  </td></tr>
<tr>
<td><code>number-sign</code>  </td><td>#  </td></tr>
<tr>
<td><code>dollar-sign</code>  </td><td>$  </td></tr>
<tr>
<td><code>percent-sign</code>  </td><td>%  </td></tr>
<tr>
<td><code>ampersand</code>  </td><td>&amp;  </td></tr>
<tr>
<td><code>apostrophe</code>  </td><td>'  </td></tr>
<tr>
<td><code>left-parenthesis</code>  </td><td>(  </td></tr>
<tr>
<td><code>right-parenthesis</code>  </td><td>)  </td></tr>
<tr>
<td><code>asterisk</code>  </td><td>*  </td></tr>
<tr>
<td><code>plus-sign</code>  </td><td>+  </td></tr>
<tr>
<td><code>comma</code>  </td><td>,  </td></tr>
<tr>
<td><code>hyphen</code>  </td><td>-  </td></tr>
</table>
<p class="endtd"></p>
</td><td><table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>hyphen-minus</code>  </td><td>-  </td></tr>
<tr>
<td><code>period</code>  </td><td>.  </td></tr>
<tr>
<td><code>full-stop</code>  </td><td>.  </td></tr>
<tr>
<td><code>slash</code>  </td><td>/  </td></tr>
<tr>
<td><code>solidus</code>  </td><td>/  </td></tr>
<tr>
<td><code>zero</code>  </td><td>0  </td></tr>
<tr>
<td><code>one</code>  </td><td>1  </td></tr>
<tr>
<td><code>two</code>  </td><td>2  </td></tr>
<tr>
<td><code>three</code>  </td><td>3  </td></tr>
<tr>
<td><code>four</code>  </td><td>4  </td></tr>
<tr>
<td><code>five</code>  </td><td>5  </td></tr>
<tr>
<td><code>six</code>  </td><td>6  </td></tr>
<tr>
<td><code>seven</code>  </td><td>7  </td></tr>
<tr>
<td><code>eight</code>  </td><td>8  </td></tr>
<tr>
<td><code>nine</code>  </td><td>9  </td></tr>
<tr>
<td><code>colon</code>  </td><td>:  </td></tr>
<tr>
<td><code>semicolon</code>  </td><td>;  </td></tr>
<tr>
<td><code>less-than-sign</code>  </td><td>&lt;  </td></tr>
<tr>
<td><code>equals-sign</code>  </td><td>=  </td></tr>
</table>
<p class="endtd"></p>
</td><td><table  class="doctable" border="1" cellspacing="0" cellpadding="3">
<tr>
<td><code>greater-than-sign</code>  </td><td>&gt;  </td></tr>
<tr>
<td><code>question-mark</code>  </td><td>?  </td></tr>
<tr>
<td><code>commercial-at</code>  </td><td>@  </td></tr>
<tr>
<td><code>left-square-bracket</code>  </td><td>[  </td></tr>
<tr>
<td><code>backslash</code>  </td><td>\  </td></tr>
<tr>
<td><code>reverse-solidus</code>  </td><td>\  </td></tr>
<tr>
<td><code>right-square-bracket</code>  </td><td>]  </td></tr>
<tr>
<td><code>circumflex</code>  </td><td>^  </td></tr>
<tr>
<td><code>circumflex-accent</code>  </td><td>^  </td></tr>
<tr>
<td><code>underscore</code>  </td><td>_  </td></tr>
<tr>
<td><code>low-line</code>  </td><td>_  </td></tr>
<tr>
<td><code>grave-accent</code>  </td><td>'  </td></tr>
<tr>
<td><code>left-brace</code>  </td><td>{  </td></tr>
<tr>
<td><code>left-curly-bracket</code>  </td><td>{  </td></tr>
<tr>
<td><code>vertical-line</code>  </td><td>|  </td></tr>
<tr>
<td><code>right-brace</code>  </td><td>}  </td></tr>
<tr>
<td><code>right-curly-bracket</code>  </td><td>}  </td></tr>
<tr>
<td><code>tilde</code>  </td><td>~  </td></tr>
<tr>
<td><code>DEL</code>  </td><td>\177  </td></tr>
</table>
<p class="endtd"></p>
</td></tr>
</table>
</center> </div></div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>