/usr/share/doublecmd/doc/en/regexp.html is in doublecmd-help-en 0.5.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Syntax of Regular Expressions</title>
<link rel="STYLESHEET" type="text/css" href="doublecmd.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<div class="CHAPTER">
<h1>Syntax of Regular Expressions</h1>
<div class="TOC">
<dl>
<dt class="bold">Content</dt>
<dt>1. <a a href="#preface">Introduction</a></dt>
<dt>2. <a a href="#compare">Simple matches</a></dt>
<dt>3. <a a href="#esc">Escape sequences</a></dt>
<dt>4. <a a href="#symbols">Character classes</a></dt>
<dt>5. <a a href="#meta">Metacharacters</a></dt>
<dd>
<dl>
<dt>5.1. <a a href="#meta-line">Metacharacters - line separators</a></dt>
<dt>5.2. <a a href="#meta-std">Metacharacters - predefined classes</a></dt>
<dt>5.3. <a a href="#meta-words">Metacharacters - word boundaries</a></dt>
<dt>5.4. <a a href="#meta-dup">Metacharacters - iterators</a></dt>
<dt>5.5. <a a href="#meta-vars">Metacharacters - alternatives</a></dt>
<dt>5.6. <a a href="#meta-sub">Metacharacters - subexpressions</a></dt>
<dt>5.7. <a a href="#meta-back">Metacharacters - backreferences</a></dt>
</dl>
</dd>
<dt>6. <a a href="#modifiers">Modifiers</a></dt>
<dt>7. <a a href="#perl">Perl extensions</a></dt>
</dl>
</div>
<hr/>
<p>Double Commander uses the free Delphi library <span class="bold">TRegExpr</span> by Andrey V. Sorokin:
<a href="http://www.regexpstudio.com/">http://www.regexpstudio.com/</a>. Most of the explanations are from the help file for this library.</p>
<div class="SECT1">
<h2><a name="preface">1. Introduction</a></h2>
<p>Regular Expressions are a widely-used method of specifying patterns of text to search for. Special <span class="bold">metacharacters</span> allow you to specify, for instance, that a particular string you are looking for occurs at the beginning or end of a line, or contains <span class="bold">n</span> recurrences of a certain character.<p>
<p>Regular expressions are mainly meant for professionals, but can also be useful in the office for finding certain documents (see examples below).</p>
<p>Double Commander supports regular expressions in the following functions:</p>
<ul>
<li><p>Commands → Search (in file name)</p></li>
<li><p>In the internal Editor</p></li>
<li><p>In the Multi-Rename tool</p></li>
</ul>
</div>
<div class="SECT1">
<h2><a name="compare">2. Simple matches</a></h2>
<p>Any single character matches itself, unless it is a metacharacter with a special meaning described below.</p>
<p>A series of characters matches that series of characters in the target string, so the pattern "bluh" would match "bluh'' in the target string. Quite simple, eh?</p>
<p>You can cause characters that normally function as metacharacters or <span class="bold">escape sequences</span> to be interpreted literally by 'escaping' them by preceding them with a backslash "\", for instance: metacharacter "^" match beginning of string, but "\^" match character "^", "\\" match "\" and so on.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foobar</tt></td>
<td>matches string 'foobar'</td>
</tr>
<tr>
<td><tt>\^FooBarPtr</tt></td>
<td>matches '^FooBarPtr'</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT1">
<h2><a name="esc">3. Escape sequences</a></h2>
<p>Characters may be specified using a escape sequences syntax much like that used in C and Perl: "\n'' matches a newline, "\t'' a tab, etc. More generally, \xnn, where nn is a string of hexadecimal digits, matches the character whose ASCII value is nn. If you need wide (Unicode) character code, you can use '\x{nnnn}', where 'nnnn' - one or more hexadecimal digits.</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>\xnn</tt></td>
<td>char with hex code nn</td>
</tr>
<tr>
<td><tt>\x{nnnn}</tt></td>
<td>char with hex code nnnn (one byte for plain text and two bytes for <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#unicode_support">Unicode</a>)</td>
</tr>
<tr>
<td><tt>\t</tt></td>
<td>tab (HT/TAB), same as \x09</td>
</tr>
<tr>
<td><tt>\n</tt></td>
<td>newline (NL), same as \x0a</td>
</tr>
<tr>
<td><tt>\r</tt></td>
<td>car.return (CR), same as \x0d</td>
</tr>
<tr>
<td><tt>\f</tt></td>
<td>form feed (FF), same as \x0c</td>
</tr>
<tr>
<td><tt>\a</tt></td>
<td>alarm (bell) (BEL), same as \x07</td>
</tr>
<tr>
<td><tt>\e</tt></td>
<td>escape (ESC), same as \x1b</td>
</tr>
</tbody>
</table>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foo\x20bar</tt></td>
<td>matches 'foo bar' (note space in the middle)</td>
</tr>
<tr>
<td><tt>\tfoobar</tt></td>
<td>matches 'foobar' predefined by tab</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT1">
<h2><a name="symbols">4. Character classes</a></h2>
<p>You can specify a character class, by enclosing a list of characters in [], which will match any <span class="bold">one</span> character from the list.</p>
<p>If the first character after the "['' is "^'', the class matches any character <span class="bold">not</span> in the list.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foob[aeiou]r</tt></td>
<td>finds strings 'foobar', 'foober' etc. but not 'foobbr', 'foobcr' etc.</td>
</tr>
<tr>
<td><tt>foob[^aeiou]r</tt></td>
<td>find strings 'foobbr', 'foobcr' etc. but not 'foobar', 'foober' etc.</td>
</tr>
</tbody>
</table>
<p>Within a list, the "-'' character is used to specify a <span class="bold">range</span>, so that a-z represents all characters between "a'' and "z'', inclusive.</p>
<p>If you want "-'' itself to be a member of a class, put it at the start or end of the list, or escape it with a backslash. If you want ']' you may place it at the start of list or escape it with a backslash.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>[-az]</tt></td>
<td>matches 'a', 'z' and '-'</td>
</tr>
<tr>
<td><tt>[az-]</tt></td>
<td>matches 'a', 'z' and '-'</td>
</tr>
<tr>
<td><tt>[a\-z]</tt></td>
<td>matches 'a', 'z' and '-'</td>
</tr>
<tr>
<td><tt>[a-z]</tt></td>
<td>matches all twenty six small characters from 'a' to 'z'</td>
</tr>
<tr>
<td><tt>[\n-\x0D]</tt></td>
<td>matches any of #10,#11,#12,#13.</td>
</tr>
<tr>
<td><tt>[\d-t]</tt></td>
<td>matches any digit, '-' or 't'.</td>
</tr>
<tr>
<td><tt>[]-a]</tt></td>
<td>matches any char from ']'..'a'.</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT1">
<h2><a name="meta">5. Metacharacters</a></h2>
<p>Metacharacters are special characters which are the essence of Regular Expressions. There are different types of metacharacters, described below.</p>
</div>
<div class="SECT2">
<h3><a id="meta-line" name="meta-line">5.1. Metacharacters - line separators</a></h3>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>^</tt></td>
<td>start of line</td>
</tr>
<tr>
<td><tt>$</tt></td>
<td>end of line</td>
</tr>
<tr>
<td><tt>\A</tt></td>
<td>start of text</td>
</tr>
<tr>
<td><tt>\Z</tt></td>
<td>end of text</td>
</tr>
<tr>
<td><tt>.</tt></td>
<td>any character in line</td>
</tr>
</tbody>
</table>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>^foobar</tt></td>
<td>matches string 'foobar' only if it's at the beginning of line</td>
</tr>
<tr>
<td><tt>foobar$</tt></td>
<td>matches string 'foobar' only if it's at the end of line</td>
</tr>
<tr>
<td><tt>^foobar$</tt></td>
<td>matches string 'foobar' only if it's the only string in line</td>
</tr>
<tr>
<td><tt>foob.r</tt></td>
<td>matches strings like 'foobar', 'foobbr', 'foob1r' and so on</td>
</tr>
</tbody>
</table>
<p>The "^" metacharacter by default is only guaranteed to match at the beginning of the input string/text, the "$" metacharacter only at the end. Embedded line separators will not be matched by "^'' or "$''.</p>
<p>You may, however, wish to treat a string as a multi-line buffer, such that the "^'' will match after any line separator within the string, and "$'' will match before any line separator. You can do this by switching On the <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_m">modifier /m</a>.</p>
<p>The \A and \Z are just like "^'' and "$'', except that they won't match multiple times when the <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_m">modifier /m</a> is used, while "^'' and "$'' will match at every internal line separator.</p>
<p>The ".'' metacharacter by default matches any character, but if you switch Off the <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_s">modifier /s</a>, then '.' won't match embedded line separators.</p>
<p>TRegExpr works with line separators as recommended at www.unicode.org ( http://www.unicode.org/unicode/reports/tr18/ ):</p>
<p>"^" is at the beginning of a input string, and, if <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_m">modifier /m</a> is On, also immediately following any occurrence of \x0D\x0A or \x0A or \x0D (if you are using <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#unicode_support">Unicode version</a> of TRegExpr, then also \x2028 or \x2029 or \x0B or \x0C or \x85). Note that there is no empty line within the sequence \x0D\x0A.</p>
<p>"$" is at the end of a input string, and, if <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_m">modifier /m</a> is On, also immediately preceding any occurrence of \x0D\x0A or \x0A or \x0D (if you are using <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#unicode_support">Unicode version</a> of TRegExpr, then also \x2028 or \x2029 or \x0B or \x0C or \x85). Note that there is no empty line within the sequence \x0D\x0A.</p>
<p>"." matches any character, but if you switch Off <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_m">modifier /s</a> then "." doesn't match \x0D\x0A and \x0A and \x0D (if you are using <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#unicode_support">Unicode version</a> of TRegExpr, then also \x2028 and \x2029 and \x0B and \x0C and \x85).</p>
<p>Note that "^.*$" (an empty line pattern) does not match the empty string within the sequence \x0D\x0A, but matches the empty string within the sequence \x0A\x0D.</p>
<p>Multi-line processing can be easily tuned for your own purpose with help of TRegExpr properties <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#lineseparators">LineSeparators</a> and <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#linepairedseparator">LinePairedSeparator</a>, you can use only Unix style separators \n or only DOS/Windows style \r\n or mix them together (as described above and used by default) or define your own line separators!</p>
</div>
<div class="SECT2">
<h3><a name="meta-std">5.2. Metacharacters - predefined classes</a></h3>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>\w</tt></td>
<td>an alphanumeric character (including "_")</td>
</tr>
<tr>
<td><tt>\W</tt></td>
<td>a nonalphanumeric</td>
</tr>
<tr>
<td><tt>\d</tt></td>
<td>a numeric character</td>
</tr>
<tr>
<td><tt>\D</tt></td>
<td>a non-numeric</td>
</tr>
<tr>
<td><tt>\s</tt></td>
<td>any space (same as [ \t\n\r\f])</td>
</tr>
<tr>
<td><tt>\S</tt></td>
<td>a non space</td>
</tr>
</tbody>
</table>
<p>You may use \w, \d and \s within custom <span class="bold">character classes</span>.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foob\dr</tt></td>
<td>matches strings like 'foob1r', ''foob6r' and so on but not 'foobar', 'foobbr' and so on</td>
</tr>
<tr>
<td><tt>foob[\w\s]r</tt></td>
<td>matches strings like 'foobar', 'foob r', 'foobbr' and so on but not 'foob1r', 'foob=r' and so on</td>
</tr>
</tbody>
</table>
<p>TRegExpr uses options <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.spacechars">SpaceChars</a> and <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.wordchars">WordChars</a> to redefine standard \w, \W, \s, \S, classes.</p>
</div>
<div class="SECT2">
<h3><a name="meta-words">5.3. Metacharacters - word boundaries</a></h3>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>\b</tt></td>
<td>Match a word boundary</td>
</tr>
<tr>
<td><tt>\B</tt></td>
<td>Match a non-(word boundary)</td>
</tr>
</tbody>
</table>
<p>A word boundary (\b) is a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \W.</p>
</div>
<div class="SECT2">
<h3><a name="meta-dup">5.4. Metacharacters - iterators</a></h3>
<p>Any item of a regular expression may be followed by another type of metacharacters - iterators. Using these metacharacters you can specify the number of occurrences of the previous character, metacharacter or subexpression.</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>*</tt></td>
<td>zero or more ("greedy"), similar to {0,}</td>
</tr>
<tr>
<td><tt>+</tt></td>
<td>one or more ("greedy"), similar to {1,}</td>
</tr>
<tr>
<td><tt>?</tt></td>
<td>zero or one ("greedy"), similar to {0,1}</td>
</tr>
<tr>
<td><tt>{n}</tt></td>
<td>exactly n times ("greedy")</td>
</tr>
<tr>
<td><tt>{n,}</tt></td>
<td>at least n times ("greedy")</td>
</tr>
<tr>
<td><tt>{n,m}</tt></td>
<td>at least n but not more than m times ("greedy")</td>
</tr>
<tr>
<td><tt>*?</tt></td>
<td>zero or more ("non-greedy"), similar to {0,}?</td>
</tr>
<tr>
<td><tt>+?</tt></td>
<td>one or more ("non-greedy"), similar to {1,}?</td>
</tr>
<tr>
<td><tt>??</tt></td>
<td>zero or one ("non-greedy"), similar to {0,1}?</td>
</tr>
<tr>
<td><tt>{n}?</tt></td>
<td>exactly n times ("non-greedy")</td>
</tr>
<tr>
<td><tt>{n,}?</tt></td>
<td>at least n times ("non-greedy")</td>
</tr>
<tr>
<td><tt>{n,m}?</tt></td>
<td>at least n but not more than m times ("non-greedy") </td>
</tr>
</tbody>
</table>
<p>So, digits in curly brackets of the form {n,m}, specify the <span class="bold">minimum</span> number of times to match the item n and the <span class="bold">maximum</span> m. The form {n} is equivalent to {n,n} and matches exactly n times. The form {n,} matches n or more times. There is no limit to the size of n or m, but large numbers will chew up more memory and slow down r.e. execution.</p>
<p>If a curly bracket occurs in any other context, it is treated as a regular character.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foob.*r</tt></td>
<td>matches strings like 'foobar', 'foobalkjdflkj9r' and 'foobr'</td>
</tr>
<tr>
<td><tt>foob.+r</tt></td>
<td>matches strings like 'foobar', 'foobalkjdflkj9r' but not 'foobr'</td>
</tr>
<tr>
<td><tt>foob.?r</tt></td>
<td>matches strings like 'foobar', 'foobbr' and 'foobr' but not 'foobalkj9r'</td>
</tr>
<tr>
<td><tt>fooba{2}r</tt></td>
<td>matches the string 'foobaar'</td>
</tr>
<tr>
<td><tt>fooba{2,}r</tt></td>
<td>matches strings like 'foobaar', 'foobaaar', 'foobaaaar' etc.</td>
</tr>
<tr>
<td><tt>fooba{2,3}r</tt></td>
<td>matches strings like 'foobaar', or 'foobaaar' but not 'foobaaaar'</td>
</tr>
</tbody>
</table>
<p>A little explanation about "greediness". "Greedy" takes as many as possible, "non-greedy" takes as few as possible. For example, 'b+' and 'b*' applied to string 'abbbbc' return 'bbbb', 'b+?' returns 'b', 'b*?' returns empty string, 'b{2,3}?' returns 'bb', 'b{2,3}' returns 'bbb'.</p>
<p>You can switch all iterators into "non-greedy" mode (see the <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_g">modifier /g</a>).</p>
</div>
<div class="SECT2">
<h3><a name="meta-vars">5.5. Metacharacters - alternatives</a></h3>
<p>You can specify a series of <span class="bold">alternatives</span> for a pattern using "|'' to separate them, so that fee|fie|foe will match any of "fee'', "fie'', or "foe'' in the target string (as would f(e|i|o)e). The first alternative includes everything from the last pattern delimiter ("('', "['', or the beginning of the pattern) up to the first "|'', and the last alternative contains everything from the last "|'' to the next pattern delimiter. For this reason, it's common practice to include alternatives in parentheses, to minimize confusion about where they start and end.</p>
<p>Alternatives are tried from left to right, so the first alternative found for which the entire expression matches, is the one that is chosen. This means that alternatives are not necessarily greedy. For example: when matching foo|foot against "barefoot'', only the "foo'' part will match, as that is the first alternative tried, and it successfully matches the target string. (This might not seem important, but it is important when you are capturing matched text using parentheses.)</p>
<p>Also remember that "|'' is interpreted as a literal within square brackets, so if you write [fee|fie|foe] you're really only matching [feio|].</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>foo(bar|foo)</tt></td>
<td>matches strings 'foobar' or 'foofoo'.</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT2">
<h3><a name="meta-sub">5.6. Metacharacters - subexpressions</a></h3>
<p>The bracketing construct ( ... ) may also be used for define r.e. subexpressions. After search you can call any subexpression using properties MatchPos, MatchLen and <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.match">Match</a>, also you can use subexpressions as masks using <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.substitute">Substitute</a>).</p>
<p>Subexpressions are numbered based on the left to right order of their opening parenthesis.</p>
<p>First subexpression has number '1' (whole r.e. match has number '0' - you can substitute it in <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.substitute">Substitute</a> as '$0' or '$&').</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>(foobar){8,10}</tt></td>
<td>matches strings which contain 8, 9 or 10 instances of the 'foobar'</td>
</tr>
<tr>
<td><tt>foob([0-9]|a+)r</tt></td>
<td>matches 'foob0r', 'foob1r' , 'foobar', 'foobaar', 'foobaar' etc.</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT2">
<h3><a name="meta-back">5.7. Metacharacters - backreferences</a></h3>
<p>Metacharacters \1 through \9 are interpreted as backreferences. \<n> matches previously matched subexpression #<n>.</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>(.)\1+</tt></td>
<td>matches 'aaaa' and 'cc'.</td>
</tr>
<tr>
<td><tt>(.+)\1+</tt></td>
<td>also match 'abab' and '123123'</td>
</tr>
<tr>
<td><tt>(['"]?)(\d+)\1</tt></td>
<td>matches '"13" (in double quotes), or '4' (in single quotes) or 77 (without quotes) etc</td>
</tr>
</tbody>
</table>
</div>
<div class="SECT1">
<h2><a name="modifiers">6. Modifiers</a></h2>
<p>Modifiers are for changing behaviour of regular expressions.</p>
<p>Any of these modifiers may be embedded within the regular expression itself using the <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#inline_modifiers">(?...)</a> construct.</p>
<dl>
<dt><tt>i</tt></dt>
<dd>Do case-insensitive pattern matching (using installed in your system locale settings), see also <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#invertcase">InvertCase</a>.</dd>
<dt><tt>m</tt></dt>
<dd>Treat string as multiple lines. That is, change "^'' and "$'' from matching at only the very start or end of the string to the start or end of any line anywhere within the string, see also <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#syntax_line_separators">Line separators</a>.</dd>
<dt><tt>s</tt></dt>
<dd>Treat string as single line. That is, change ".'' to match any character whatsoever, even a line separator (see also <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#syntax_line_separators">Line separators</a>), which it normally would not match.</dd>
<dt><tt>g</tt></dt>
<dd>Non standard modifier. Switching it Off you'll switch all following operators into non-greedy mode (by default this modifier is On). So, if modifier /g is Off then '+' works as '+?', '*' as '*?' and so on </dd>
<dt><tt>x</tt></dt>
<dd>Extend your pattern's legibility by permitting whitespace and comments (see explanation below).</dd>
<dt><tt>r</tt></dt>
<dd>Non-standard modifier. If is set then range 'а-я' additional include Russian letter 'ё', 'А-Я' additional include 'Ё', and 'а-Я' include all Russian symbols.
Sorry for foreign users, but it's set by default. If you want switch if off by default - set false to global variable <a href="http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#modifier_defs">RegExprModifierR</a>.</dd>
</dl>
<p>The <a href="http://www.regexpstudio.com/TRegExpr/Help/regexp_syntax.html#modifier_x">modifier /x</a> itself needs a little more explanation. It tells to ignore whitespace that is neither backslashed nor within a character class. You can use this to break up your regular expression into (slightly) more readable parts. The # character is also treated as a metacharacter introducing a comment, for example:</p>
<pre class="CODE">
(
(abc) # comment 1
| # You can use spaces to format r.e. - TRegExpr ignores it
(efg) # comment 2
)</pre>
<p>This also means that if you want real whitespace or # characters in the pattern (outside a character class, where they are unaffected by /x), that you'll either have to escape them or encode them using octal or hex escapes. Taken together, these features go a long way towards making regular expressions text more readable.</p>
</div>
<div class="SECT1">
<h2><a name="perl">7. Perl extensions</a></h2>
<p class="bold">(?imsxr-imsxr)</p>
<p>You may use it into r.e. for modifying modifiers by the fly. If this construction is inlined into subexpression, then it effects only into this subexpression</p>
<p class="bold">Examples:</p>
<table border="0" frame="void" width="100%" class="CALSTABLE">
<tbody>
<tr>
<td><tt>(?i)Saint-Petersburg</tt></td>
<td>matches 'Saint-petersburg' and 'Saint-Petersburg'</td>
</tr>
<tr>
<td><tt>(?i)Saint-(?-i)Petersburg</tt></td>
<td>matches 'Saint-Petersburg' but not 'Saint-petersburg'</td>
</tr>
<tr>
<td><tt>(?i)(Saint-)?Petersburg</tt></td>
<td>matches 'Saint-petersburg' and 'saint-petersburg'</td>
</tr>
<tr>
<td><tt>((?i)Saint-)?Petersburg</tt></td>
<td>matches 'saint-Petersburg', but not 'saint-petersburg'</td>
</tr>
</tbody>
</table>
<p class="bold">(?#text)</p>
<p>A comment, the text is ignored. Note that TRegExpr closes the comment as soon as it sees a ")", so there is no way to put a literal ")" in the comment.</p>
</div>
<div class="SECT1">
<p class="NAVBACK"><a href="index.html">Home</a></p>
</div>
</div>
</body>
</html>
|