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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
/-- These tests are for the Perl >= 5.10 features that PCRE supports. --/
/\H\h\V\v/
X X\x0a
X\x09X\x0b
** Failers
\xa0 X\x0a
/\H*\h+\V?\v{3,4}/
\x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
\x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
\x09\x20\xa0\x0a\x0b\x0c
** Failers
\x09\x20\xa0\x0a\x0b
/\H{3,4}/
XY ABCDE
XY PQR ST
/.\h{3,4}./
XY AB PQRS
/\h*X\h?\H+Y\H?Z/
>XNNNYZ
> X NYQZ
** Failers
>XYZ
> X NY Z
/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
>XY\x0aZ\x0aA\x0bNN\x0c
>\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
/(foo)\Kbar/
foobar
/(foo)(\Kbar|baz)/
foobar
foobaz
/(foo\Kbar)baz/
foobarbaz
/abc\K|def\K/g+
Xabcdefghi
/ab\Kc|de\Kf/g+
Xabcdefghi
/(?=C)/g+
ABCDECBA
/^abc\K/+
abcdef
** Failers
defabcxyz
/^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-02}Z/
ababababbbabZXXXX
/(?<A>tom|bon)-\g{A}/
tom-tom
bon-bon
/(^(a|b\g{-1}))/
bacxxx
/(?|(abc)|(xyz))\1/
abcabc
xyzxyz
** Failers
abcxyz
xyzabc
/(?|(abc)|(xyz))(?1)/
abcabc
xyzabc
** Failers
xyzxyz
/^X(?5)(a)(?|(b)|(q))(c)(d)(Y)/
XYabcdY
/^X(?7)(a)(?|(b|(r)(s))|(q))(c)(d)(Y)/
XYabcdY
/^X(?7)(a)(?|(b|(?|(r)|(t))(s))|(q))(c)(d)(Y)/
XYabcdY
/(?'abc'\w+):\k<abc>{2}/
a:aaxyz
ab:ababxyz
** Failers
a:axyz
ab:abxyz
/(?'abc'\w+):\g{abc}{2}/
a:aaxyz
ab:ababxyz
** Failers
a:axyz
ab:abxyz
/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
abd
ce
/^(a.)\g-1Z/
aXaXZ
/^(a.)\g{-1}Z/
aXaXZ
/^(?(DEFINE) (?<A> a) (?<B> b) ) (?&A) (?&B) /x
abcd
/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
(?(DEFINE)
(?<NAME_PAT>[a-z]+)
(?<ADDRESS_PAT>\d+)
)/x
metcalfe 33
/(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
1.2.3.4
131.111.10.206
10.0.0.0
** Failers
10.6
455.3.4.5
/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
1.2.3.4
131.111.10.206
10.0.0.0
** Failers
10.6
455.3.4.5
/^(\w++|\s++)*$/
now is the time for all good men to come to the aid of the party
*** Failers
this is not a line with only words and spaces!
/(\d++)(\w)/
12345a
*** Failers
12345+
/a++b/
aaab
/(a++b)/
aaab
/(a++)b/
aaab
/([^()]++|\([^()]*\))+/
((abc(ade)ufh()()x
/\(([^()]++|\([^()]+\))+\)/
(abc)
(abc(def)xyz)
*** Failers
((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
/^([^()]|\((?1)*\))*$/
abc
a(b)c
a(b(c))d
*** Failers)
a(b(c)d
/^>abc>([^()]|\((?1)*\))*<xyz<$/
>abc>123<xyz<
>abc>1(2)3<xyz<
>abc>(1(2)3)<xyz<
/^(?:((.)(?1)\2|)|((.)(?3)\4|.))$/i
1221
Satanoscillatemymetallicsonatas
AmanaplanacanalPanama
AblewasIereIsawElba
*** Failers
Thequickbrownfox
/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/
12
(((2+2)*-3)-7)
-12
*** Failers
((2+2)*-3)-7)
/^(x(y|(?1){2})z)/
xyz
xxyzxyzz
*** Failers
xxyzz
xxyzxyzxyzz
/((< (?: (?(R) \d++ | [^<>]*+) | (?2)) * >))/x
<>
<abcd>
<abc <123> hij>
<abc <def> hij>
<abc<>def>
<abc<>
*** Failers
<abc
/^a+(*FAIL)/
aaaaaa
/a+b?c+(*FAIL)/
aaabccc
/a+b?(*PRUNE)c+(*FAIL)/
aaabccc
/a+b?(*COMMIT)c+(*FAIL)/
aaabccc
/a+b?(*SKIP)c+(*FAIL)/
aaabcccaaabccc
/^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
aaaxxxxxx
aaa++++++
bbbxxxxx
bbb+++++
cccxxxx
ccc++++
dddddddd
/^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
aaaxxxxxx
aaa++++++
bbbxxxxx
bbb+++++
cccxxxx
ccc++++
dddddddd
/a+b?(*THEN)c+(*FAIL)/
aaabccc
/(A (A|B(*ACCEPT)|C) D)(E)/x
AB
ABX
AADE
ACDE
** Failers
AD
/^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$/i
1221
Satan, oscillate my metallic sonatas!
A man, a plan, a canal: Panama!
Able was I ere I saw Elba.
*** Failers
The quick brown fox
/^((.)(?1)\2|.)$/
a
aba
aabaa
abcdcba
pqaabaaqp
ablewasiereisawelba
rhubarb
the quick brown fox
/(a)(?<=b(?1))/
baz
** Failers
caz
/(?<=b(?1))(a)/
zbaaz
** Failers
aaa
/(?<X>a)(?<=b(?&X))/
baz
/^(?|(abc)|(def))\1/
abcabc
defdef
** Failers
abcdef
defabc
/^(?|(abc)|(def))(?1)/
abcabc
defabc
** Failers
defdef
abcdef
/(?:a(?<quote> (?<apostrophe>')|(?<realquote>")) |b(?<quote> (?<apostrophe>')|(?<realquote>")) ) (?('quote')[a-z]+|[0-9]+)/xJ
a\"aaaaa
b\"aaaaa
** Failers
b\"11111
/(?:(?1)|B)(A(*F)|C)/
ABCD
CCD
** Failers
CAD
/^(?:(?1)|B)(A(*F)|C)/
CCD
BCD
** Failers
ABCD
CAD
BAD
/(?:(?1)|B)(A(*ACCEPT)XX|C)D/
AAD
ACD
BAD
BCD
BAX
** Failers
ACX
ABC
/(?(DEFINE)(A))B(?1)C/
BAC
/(?(DEFINE)((A)\2))B(?1)C/
BAAC
/(?<pn> \( ( [^()]++ | (?&pn) )* \) )/x
(ab(cd)ef)
/^(?!a(*SKIP)b)/
ac
/^(?=a(*SKIP)b|ac)/
** Failers
ac
/^(?=a(*THEN)b|ac)/
ac
/^(?=a(*PRUNE)b)/
ab
** Failers
ac
/^(?=a(*ACCEPT)b)/
ac
/^(?(?!a(*SKIP)b))/
ac
/(?>a\Kb)/
ab
/((?>a\Kb))/
ab
/(a\Kb)/
ab
/^a\Kcz|ac/
ac
/(?>a\Kbz|ab)/
ab
/^(?&t)(?(DEFINE)(?<t>a\Kb))$/
ab
/^([^()]|\((?1)*\))*$/
a(b)c
a(b(c)d)e
/(?P<L1>(?P<L2>0)(?P>L1)|(?P>L2))/
0
00
0000
/(?P<L1>(?P<L2>0)|(?P>L2)(?P>L1))/
0
00
0000
/--- This one does fail, as expected, in Perl. It needs the complex item at the
end of the pattern. A single letter instead of (B|D) makes it not fail,
which I think is a Perl bug. --- /
/A(*COMMIT)(B|D)/
ACABX
/--- Check the use of names for failure ---/
/^(A(*PRUNE:A)B|C(*PRUNE:B)D)/K
** Failers
AC
CB
/--- Force no study, otherwise mark is not seen. The studied version is in
test 2 because it isn't Perl-compatible. ---/
/(*MARK:A)(*SKIP:B)(C|X)/KSS
C
D
/^(A(*THEN:A)B|C(*THEN:B)D)/K
** Failers
CB
/^(?:A(*THEN:A)B|C(*THEN:B)D)/K
CB
/^(?>A(*THEN:A)B|C(*THEN:B)D)/K
CB
/--- This should succeed, as the skip causes bump to offset 1 (the mark). Note
that we have to have something complicated such as (B|Z) at the end because,
for Perl, a simple character somehow causes an unwanted optimization to mess
with the handling of backtracking verbs. ---/
/A(*MARK:A)A+(*SKIP:A)(B|Z) | AC/xK
AAAC
/--- Test skipping over a non-matching mark. ---/
/A(*MARK:A)A+(*MARK:B)(*SKIP:A)(B|Z) | AC/xK
AAAC
/--- Check shorthand for MARK ---/
/A(*:A)A+(*SKIP:A)(B|Z) | AC/xK
AAAC
/--- Don't loop! Force no study, otherwise mark is not seen. ---/
/(*:A)A+(*SKIP:A)(B|Z)/KSS
AAAC
/--- This should succeed, as a non-existent skip name disables the skip ---/
/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/xK
AAAC
/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC(*:B)/xK
AAAC
/--- We use something more complicated than individual letters here, because
that causes different behaviour in Perl. Perhaps it disables some optimization;
anyway, the result now matches PCRE in that no tag is passed back for the
failures. ---/
/(A|P)(*:A)(B|P) | (X|P)(X|P)(*:B)(Y|P)/xK
AABC
XXYZ
** Failers
XAQQ
XAQQXZZ
AXQQQ
AXXQQQ
/--- COMMIT at the start of a pattern should act like an anchor. Again,
however, we need the complication for Perl. ---/
/(*COMMIT)(A|P)(B|P)(C|P)/
ABCDEFG
** Failers
DEFGABC
/--- COMMIT inside an atomic group can't stop backtracking over the group. ---/
/(\w+)(?>b(*COMMIT))\w{2}/
abbb
/(\w+)b(*COMMIT)\w{2}/
abbb
/--- Check opening parens in comment when seeking forward reference. ---/
/(?&t)(?#()(?(DEFINE)(?<t>a))/
bac
/--- COMMIT should override THEN ---/
/(?>(*COMMIT)(?>yes|no)(*THEN)(*F))?/
yes
/(?>(*COMMIT)(yes|no)(*THEN)(*F))?/
yes
/^((yes|no)(*THEN)(*F))?/
yes
/b?(*SKIP)c/
bc
abc
/(*SKIP)bc/
a
/(*SKIP)b/
a
/(?P<abn>(?P=abn)xxx|)+/
xxx
/(?i:([^b]))(?1)/
aa
aA
** Failers
ab
aB
Ba
ba
/^(?&t)*+(?(DEFINE)(?<t>a))\w$/
aaaaaaX
** Failers
aaaaaa
/^(?&t)*(?(DEFINE)(?<t>a))\w$/
aaaaaaX
aaaaaa
/^(a)*+(\w)/
aaaaX
YZ
** Failers
aaaa
/^(?:a)*+(\w)/
aaaaX
YZ
** Failers
aaaa
/^(a)++(\w)/
aaaaX
** Failers
aaaa
YZ
/^(?:a)++(\w)/
aaaaX
** Failers
aaaa
YZ
/^(a)?+(\w)/
aaaaX
YZ
/^(?:a)?+(\w)/
aaaaX
YZ
/^(a){2,}+(\w)/
aaaaX
** Failers
aaa
YZ
/^(?:a){2,}+(\w)/
aaaaX
** Failers
aaa
YZ
/(a|)*(?1)b/
b
ab
aab
/(a)++(?1)b/
** Failers
ab
aab
/(a)*+(?1)b/
** Failers
ab
aab
/(?1)(?:(b)){0}/
b
/(foo ( \( ((?:(?> [^()]+ )|(?2))*) \) ) )/x
foo(bar(baz)+baz(bop))
/(A (A|B(*ACCEPT)|C) D)(E)/x
AB
/\A.*?(?:a|b(*THEN)c)/
ba
/\A.*?(?:a|bc)/
ba
/\A.*?(a|b(*THEN)c)/
ba
/\A.*?(a|bc)/
ba
/\A.*?(?:a|b(*THEN)c)++/
ba
/\A.*?(?:a|bc)++/
ba
/\A.*?(a|b(*THEN)c)++/
ba
/\A.*?(a|bc)++/
ba
/\A.*?(?:a|b(*THEN)c|d)/
ba
/\A.*?(?:a|bc|d)/
ba
/(?:(b))++/
beetle
/(?(?=(a(*ACCEPT)z))a)/
a
/^(a)(?1)+ab/
aaaab
/^(a)(?1)++ab/
aaaab
/-- End of testinput11 --/
|