File: pcresyntax.texi

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (583 lines) | stat: -rw-r--r-- 11,915 bytes parent folder | download | duplicates (5)
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
@c This file was hand-translated to Texinfo from the upstream PCRE
@c documentation file pcresyntax.3, whose copyright notice is:
@c
@c Author: Philip Hazel, University Computing Service
@c Cambridge CB2 3QH, England
@c Last updated: 21 September 2007
@c Copyright (c) 1997-2007 University of Cambridge.
@c
@c Redistribution and use in source and binary forms, with or without
@c modification, are permitted provided that the following conditions are met:
@c
@c     * Redistributions of source code must retain the above copyright notice,
@c       this list of conditions and the following disclaimer.
@c
@c     * Redistributions in binary form must reproduce the above copyright
@c       notice, this list of conditions and the following disclaimer in the
@c       documentation and/or other materials provided with the distribution.
@c
@c     * Neither the name of the University of Cambridge nor the names of its
@c       contributors may be used to endorse or promote products derived from
@c       this software without specific prior written permission.
@c
@c THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
@c AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@c IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@c ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
@c LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
@c CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
@c SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@c INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@c CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
@c ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
@c POSSIBILITY OF SUCH DAMAGE.
@c
@c Apart from markup translation, all mention of callouts has been
@c removed, and a few confusing references to PCRE itself or to
@c specific programming environments have been removed or clarified.

@node Regexp Summary
@subsection Regexp Syntax Summary

This is a quick-reference summary of the regular expression syntax
used in Monotone.

@subsubheading Quoting

@table @code
@item \@var{x}
  where @var{x} is non-alphanumeric is a literal @var{x}
@item \Q...\E
  treat enclosed characters as literal
@end table

@subsubheading Characters

@table @code
@item \a
  alarm, that is, the BEL character (hex 07)
@item \c@var{x}
  ``control-@var{x}'', where @var{x} is any character
@item \e
  escape (hex 1B)
@item \f
  formfeed (hex 0C)
@item \n
  newline (hex 0A)
@item \r
  carriage return (hex 0D)
@item \t
  tab (hex 09)
@item \@var{ddd}
  character with octal code @var{ddd}, or backreference
@item \x@var{hh}
  character with hex code @var{hh}
@item \x@{@var{hhh...}@}
  character with hex code @var{hhh...}
@end table

@subsubheading Character Types

@table @code
@item .
  any character except newline;
               in dotall mode, any character whatsoever
@item \C
  one byte, even in UTF-8 mode (best avoided)
@item \d
  a decimal digit
@item \D
  a character that is not a decimal digit
@item \h
  a horizontal whitespace character
@item \H
  a character that is not a horizontal whitespace character
@item \p@{@var{xx}@}
  a character with the @var{xx} property
@item \P@{@var{xx}@}
  a character without the @var{xx} property
@item \R
  a newline sequence
@item \s
  a whitespace character
@item \S
  a character that is not a whitespace character
@item \v
  a vertical whitespace character
@item \V
  a character that is not a vertical whitespace character
@item \w
  a ``word'' character
@item \W
  a ``non-word'' character
@item \X
  an extended Unicode sequence
@end table

@noindent
@samp{\d}, @samp{\D}, @samp{\s}, @samp{\S}, @samp{\w}, and @samp{\W}
recognize only ASCII characters.

@subsubheading General category property codes for @samp{\p} and @samp{\P}

@table @code
@item C
  Other
@item Cc
  Control
@item Cf
  Format
@item Cn
  Unassigned
@item Co
  Private use
@item Cs
  Surrogate

@item L
  Letter
@item Ll
  Lower case letter
@item Lm
  Modifier letter
@item Lo
  Other letter
@item Lt
  Title case letter
@item Lu
  Upper case letter
@item L&
  Ll, Lu, or Lt

@item M
  Mark
@item Mc
  Spacing mark
@item Me
  Enclosing mark
@item Mn
  Non-spacing mark

@item N
  Number
@item Nd
  Decimal number
@item Nl
  Letter number
@item No
  Other number

@item P
  Punctuation
@item Pc
  Connector punctuation
@item Pd
  Dash punctuation
@item Pe
  Close punctuation
@item Pf
  Final punctuation
@item Pi
  Initial punctuation
@item Po
  Other punctuation
@item Ps
  Open punctuation

@item S
  Symbol
@item Sc
  Currency symbol
@item Sk
  Modifier symbol
@item Sm
  Mathematical symbol
@item So
  Other symbol

@item Z
  Separator
@item Zl
  Line separator
@item Zp
  Paragraph separator
@item Zs
  Space separator
@end table

@subsubheading Script names for @samp{\p} and @samp{\P}

Arabic,
Armenian,
Balinese,
Bengali,
Bopomofo,
Braille,
Buginese,
Buhid,
Canadian_Aboriginal,
Cherokee,
Common,
Coptic,
Cuneiform,
Cypriot,
Cyrillic,
Deseret,
Devanagari,
Ethiopic,
Georgian,
Glagolitic,
Gothic,
Greek,
Gujarati,
Gurmukhi,
Han,
Hangul,
Hanunoo,
Hebrew,
Hiragana,
Inherited,
Kannada,
Katakana,
Kharoshthi,
Khmer,
Lao,
Latin,
Limbu,
Linear_B,
Malayalam,
Mongolian,
Myanmar,
New_Tai_Lue,
Nko,
Ogham,
Old_Italic,
Old_Persian,
Oriya,
Osmanya,
Phags_Pa,
Phoenician,
Runic,
Shavian,
Sinhala,
Syloti_Nagri,
Syriac,
Tagalog,
Tagbanwa,
Tai_Le,
Tamil,
Telugu,
Thaana,
Thai,
Tibetan,
Tifinagh,
Ugaritic,
Yi.

@subsubheading Character Classes

@table @code
@item [...]
  positive character class
@item [^...]
  negative character class
@item [@var{x}-@var{y}]
  range (can be used for hex characters)
@item [[:@var{xxx}:]]
  positive POSIX named set
@item [[:^@var{xxx}:]]
  negative POSIX named set

@item alnum
  alphanumeric
@item alpha
  alphabetic
@item ascii
  0-127
@item blank
  space or tab
@item cntrl
  control character
@item digit
  decimal digit
@item graph
  printing, excluding space
@item lower
  lower case letter
@item print
  printing, including space
@item punct
  printing, excluding alphanumeric
@item space
  whitespace
@item upper
  upper case letter
@item word
  same as @samp{\w}
@item xdigit
  hexadecimal digit
@end table

In PCRE, POSIX character set names recognize only ASCII
characters. You can use @samp{\Q...\E} inside a character class.

@subsubheading Quantifiers

@table @code
@item ?
  0 or 1, greedy
@item ?+
  0 or 1, possessive
@item ??
  0 or 1, lazy
@item *
  0 or more, greedy
@item *+
  0 or more, possessive
@item *?
  0 or more, lazy
@item +
  1 or more, greedy
@item ++
  1 or more, possessive
@item +?
  1 or more, lazy
@item @{@var{n}@}
  exactly @var{n}
@item @{@var{n},@var{m}@}
  at least @var{n}, no more than @var{m}, greedy
@item @{@var{n},@var{m}@}+
  at least @var{n}, no more than @var{m}, possessive
@item @{@var{n},@var{m}@}?
  at least @var{n}, no more than @var{m}, lazy
@item @{@var{n},@}
  @var{n} or more, greedy
@item @{@var{n},@}+
  @var{n} or more, possessive
@item @{@var{n},@}?
  @var{n} or more, lazy
@end table

@subsubheading Anchors and Simple Assertions

@table @code
@item \b
  word boundary
@item \B
  not a word boundary
@item ^
  start of subject
               also after internal newline in multiline mode
@item \A
  start of subject
@item $
  end of subject
               also before newline at end of subject
               also before internal newline in multiline mode
@item \Z
  end of subject
               also before newline at end of subject
@item \z
  end of subject
@item \G
  first matching position in subject
@end table

@subsubheading Match Point Reset

@table @code
@item \K
  reset start of match
@end table

@subsubheading Alternation

@table @code
@item @var{expr}|@var{expr}|@var{expr}...
@end table

@subsubheading Capturing

@table @code
@item (...)
  capturing group
@item (?<@var{name}>...)
  named capturing group (like Perl)
@item (?'@var{name}'...)
  named capturing group (like Perl)
@item (?P<@var{name}>...)
  named capturing group (like Python)
@item (?:...)
  non-capturing group
@item (?|...)
  non-capturing group; reset group numbers for
  capturing groups in each alternative
@end table

@subsubheading Atomic Groups

@table @code
@item (?>...)
  atomic, non-capturing group
@end table

@subsubheading Comment

@table @code
@item (?#....)
  comment (not nestable)
@end table

@subsubheading Option Setting

@table @code
@item (?i)
  caseless
@item (?J)
  allow duplicate names
@item (?m)
  multiline
@item (?s)
  single line (dotall)
@item (?U)
  default ungreedy (lazy)
@item (?x)
  extended (ignore white space)
@item (?-...)
  unset option(s)
@end table

@subsubheading Lookahead and Lookbehind Assertions

@table @code
@item (?=...)
  positive look ahead
@item (?!...)
  negative look ahead
@item (?<=...)
  positive look behind
@item (?<!...)
  negative look behind
@end table

Each top-level branch of a look behind must be of a fixed length.

@subsubheading Backreferences

@table @code
@item \@var{n}
  reference by number (can be ambiguous)
@item \g@var{n}
  reference by number
@item \g@{@var{n}@}
  reference by number
@item \g@{-@var{n}@}
  relative reference by number
@item \k<@var{name}>
  reference by name (like Perl)
@item \k'@var{name}'
  reference by name (like Perl)
@item \g@{@var{name}@}
  reference by name (like Perl)
@item \k@{@var{name}@}
  reference by name (like .NET)
@item (?P=@var{name})
  reference by name (like Python)
@end table

@subsubheading Subroutine References (possibly recursive)

@table @code
@item (?R)
  recurse whole pattern
@item (?@var{n})
  call subpattern by absolute number
@item (?+@var{n})
  call subpattern by relative number
@item (?-@var{n})
  call subpattern by relative number
@item (?&@var{name})
  call subpattern by name (like Perl)
@item (?P>@var{name})
  call subpattern by name (like Python)
@end table

@subsubheading Conditional Patterns

@table @code
@item (?(@var{condition})@var{yes-pattern})
@item (?(@var{condition})@var{yes-pattern}|@var{no-pattern})

@item (?(@var{n})...
  absolute reference condition
@item (?(+@var{n})...
  relative reference condition
@item (?(-@var{n})...
  relative reference condition
@item (?(<@var{name}>)...
  named reference condition (like Perl)
@item (?('@var{name}')...
  named reference condition (like Perl)
@item (?(@var{name})...
  named reference condition (PCRE only)
@item (?(R)...
  overall recursion condition
@item (?(R@var{n})...
  specific group recursion condition
@item (?(R&@var{name})...
  specific recursion condition
@item (?(DEFINE)...
  define subpattern for reference
@item (?(assert)...
  assertion condition
@end table

@subsubheading Backtracking Control

The following act immediately they are reached:

@table @code
@item (*ACCEPT)
  force successful match
@item (*FAIL)
  force backtrack; synonym @samp{(*F)}
@end table

The following act only when a subsequent match failure causes a backtrack to
reach them. They all force a match failure, but they differ in what happens
afterwards. Those that advance the start-of-match point do so only if the
pattern is not anchored.

@table @code
@item (*COMMIT)
  overall failure, no advance of starting point
@item (*PRUNE)
  advance to next starting character
@item (*SKIP)
  advance start to current matching position
@item (*THEN)
  local failure, backtrack to next alternation
@end table

@subsubheading Newline Conventions

These are recognized only at the very start of the pattern or after a
@samp{(*BSR_...)} option.

@table @code
@item (*CR)
@item (*LF)
@item (*CRLF)
@item (*ANYCRLF)
@item (*ANY)
@end table

@subsubheading What @samp{\R} Matches

These are recognized only at the very start of the pattern or after a
@samp{(*...)} option that sets the newline convention.

@table @code
@item (*BSR_ANYCRLF)
@item (*BSR_UNICODE)
@end table