• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/-- These tests are for the Perl >= 5.10 features that PCRE supports. --/
2
3/\H\h\V\v/
4    X X\x0a
5    X\x09X\x0b
6    ** Failers
7    \xa0 X\x0a
8
9/\H*\h+\V?\v{3,4}/
10    \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
11    \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
12    \x09\x20\xa0\x0a\x0b\x0c
13    ** Failers
14    \x09\x20\xa0\x0a\x0b
15
16/\H{3,4}/
17    XY  ABCDE
18    XY  PQR ST
19
20/.\h{3,4}./
21    XY  AB    PQRS
22
23/\h*X\h?\H+Y\H?Z/
24    >XNNNYZ
25    >  X NYQZ
26    ** Failers
27    >XYZ
28    >  X NY Z
29
30/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
31    >XY\x0aZ\x0aA\x0bNN\x0c
32    >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
33
34/(foo)\Kbar/
35    foobar
36
37/(foo)(\Kbar|baz)/
38    foobar
39    foobaz
40
41/(foo\Kbar)baz/
42    foobarbaz
43
44/abc\K|def\K/g+
45    Xabcdefghi
46
47/ab\Kc|de\Kf/g+
48    Xabcdefghi
49
50/(?=C)/g+
51    ABCDECBA
52
53/^abc\K/+
54    abcdef
55    ** Failers
56    defabcxyz
57
58/^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-02}Z/
59    ababababbbabZXXXX
60
61/(?<A>tom|bon)-\g{A}/
62    tom-tom
63    bon-bon
64
65/(^(a|b\g{-1}))/
66    bacxxx
67
68/(?|(abc)|(xyz))\1/
69    abcabc
70    xyzxyz
71    ** Failers
72    abcxyz
73    xyzabc
74
75/(?|(abc)|(xyz))(?1)/
76    abcabc
77    xyzabc
78    ** Failers
79    xyzxyz
80
81/^X(?5)(a)(?|(b)|(q))(c)(d)(Y)/
82    XYabcdY
83
84/^X(?7)(a)(?|(b|(r)(s))|(q))(c)(d)(Y)/
85    XYabcdY
86
87/^X(?7)(a)(?|(b|(?|(r)|(t))(s))|(q))(c)(d)(Y)/
88    XYabcdY
89
90/(?'abc'\w+):\k<abc>{2}/
91    a:aaxyz
92    ab:ababxyz
93    ** Failers
94    a:axyz
95    ab:abxyz
96
97/(?'abc'\w+):\g{abc}{2}/
98    a:aaxyz
99    ab:ababxyz
100    ** Failers
101    a:axyz
102    ab:abxyz
103
104/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
105    abd
106    ce
107
108/^(a.)\g-1Z/
109    aXaXZ
110
111/^(a.)\g{-1}Z/
112    aXaXZ
113
114/^(?(DEFINE) (?<A> a) (?<B> b) )  (?&A) (?&B) /x
115    abcd
116
117/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
118  (?(DEFINE)
119  (?<NAME_PAT>[a-z]+)
120  (?<ADDRESS_PAT>\d+)
121  )/x
122    metcalfe 33
123
124/(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
125    1.2.3.4
126    131.111.10.206
127    10.0.0.0
128    ** Failers
129    10.6
130    455.3.4.5
131
132/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
133    1.2.3.4
134    131.111.10.206
135    10.0.0.0
136    ** Failers
137    10.6
138    455.3.4.5
139
140/^(\w++|\s++)*$/
141    now is the time for all good men to come to the aid of the party
142    *** Failers
143    this is not a line with only words and spaces!
144
145/(\d++)(\w)/
146    12345a
147    *** Failers
148    12345+
149
150/a++b/
151    aaab
152
153/(a++b)/
154    aaab
155
156/(a++)b/
157    aaab
158
159/([^()]++|\([^()]*\))+/
160    ((abc(ade)ufh()()x
161
162/\(([^()]++|\([^()]+\))+\)/
163    (abc)
164    (abc(def)xyz)
165    *** Failers
166    ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
167
168/^([^()]|\((?1)*\))*$/
169    abc
170    a(b)c
171    a(b(c))d
172    *** Failers)
173    a(b(c)d
174
175/^>abc>([^()]|\((?1)*\))*<xyz<$/
176   >abc>123<xyz<
177   >abc>1(2)3<xyz<
178   >abc>(1(2)3)<xyz<
179
180/^(?:((.)(?1)\2|)|((.)(?3)\4|.))$/i
181    1221
182    Satanoscillatemymetallicsonatas
183    AmanaplanacanalPanama
184    AblewasIereIsawElba
185    *** Failers
186    Thequickbrownfox
187
188/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/
189    12
190    (((2+2)*-3)-7)
191    -12
192    *** Failers
193    ((2+2)*-3)-7)
194
195/^(x(y|(?1){2})z)/
196    xyz
197    xxyzxyzz
198    *** Failers
199    xxyzz
200    xxyzxyzxyzz
201
202/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/x
203    <>
204    <abcd>
205    <abc <123> hij>
206    <abc <def> hij>
207    <abc<>def>
208    <abc<>
209    *** Failers
210    <abc
211
212/^a+(*FAIL)/
213    aaaaaa
214
215/a+b?c+(*FAIL)/
216    aaabccc
217
218/a+b?(*PRUNE)c+(*FAIL)/
219    aaabccc
220
221/a+b?(*COMMIT)c+(*FAIL)/
222    aaabccc
223
224/a+b?(*SKIP)c+(*FAIL)/
225    aaabcccaaabccc
226
227/^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
228    aaaxxxxxx
229    aaa++++++
230    bbbxxxxx
231    bbb+++++
232    cccxxxx
233    ccc++++
234    dddddddd
235
236/^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
237    aaaxxxxxx
238    aaa++++++
239    bbbxxxxx
240    bbb+++++
241    cccxxxx
242    ccc++++
243    dddddddd
244
245/a+b?(*THEN)c+(*FAIL)/
246    aaabccc
247
248/(A (A|B(*ACCEPT)|C) D)(E)/x
249    ABX
250    AADE
251    ACDE
252    ** Failers
253    AD
254
255/^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$/i
256    1221
257    Satan, oscillate my metallic sonatas!
258    A man, a plan, a canal: Panama!
259    Able was I ere I saw Elba.
260    *** Failers
261    The quick brown fox
262
263/^((.)(?1)\2|.)$/
264    a
265    aba
266    aabaa
267    abcdcba
268    pqaabaaqp
269    ablewasiereisawelba
270    rhubarb
271    the quick brown fox
272
273/(a)(?<=b(?1))/
274    baz
275    ** Failers
276    caz
277
278/(?<=b(?1))(a)/
279    zbaaz
280    ** Failers
281    aaa
282
283/(?<X>a)(?<=b(?&X))/
284    baz
285
286/^(?|(abc)|(def))\1/
287    abcabc
288    defdef
289    ** Failers
290    abcdef
291    defabc
292
293/^(?|(abc)|(def))(?1)/
294    abcabc
295    defabc
296    ** Failers
297    defdef
298    abcdef
299
300/(?:a(?<quote> (?<apostrophe>')|(?<realquote>")) |b(?<quote> (?<apostrophe>')|(?<realquote>")) ) (?('quote')[a-z]+|[0-9]+)/xJ
301    a\"aaaaa
302    b\"aaaaa
303    ** Failers
304    b\"11111
305
306/(?:(?1)|B)(A(*F)|C)/
307    ABCD
308    CCD
309    ** Failers
310    CAD
311
312/^(?:(?1)|B)(A(*F)|C)/
313    CCD
314    BCD
315    ** Failers
316    ABCD
317    CAD
318    BAD
319
320/(?:(?1)|B)(A(*ACCEPT)XX|C)D/
321    AAD
322    ACD
323    BAD
324    BCD
325    BAX
326    ** Failers
327    ACX
328    ABC
329
330/(?(DEFINE)(A))B(?1)C/
331    BAC
332
333/(?(DEFINE)((A)\2))B(?1)C/
334    BAAC
335
336/(?<pn> \( ( [^()]++ | (?&pn) )* \) )/x
337    (ab(cd)ef)
338
339/^(?!a(*SKIP)b)/
340    ac
341
342/^(?=a(*SKIP)b|ac)/
343    ** Failers
344    ac
345
346/^(?=a(*THEN)b|ac)/
347    ac
348
349/^(?=a(*PRUNE)b)/
350    ab
351    ** Failers
352    ac
353
354/^(?=a(*ACCEPT)b)/
355    ac
356
357/^(?(?!a(*SKIP)b))/
358    ac
359
360/(?>a\Kb)/
361    ab
362
363/((?>a\Kb))/
364    ab
365
366/(a\Kb)/
367    ab
368
369/^a\Kcz|ac/
370    ac
371
372/(?>a\Kbz|ab)/
373    ab
374
375/^(?&t)(?(DEFINE)(?<t>a\Kb))$/
376    ab
377
378/^([^()]|\((?1)*\))*$/
379    a(b)c
380    a(b(c)d)e
381
382/(?P<L1>(?P<L2>0)(?P>L1)|(?P>L2))/
383    0
384    00
385    0000
386
387/(?P<L1>(?P<L2>0)|(?P>L2)(?P>L1))/
388    0
389    00
390    0000
391
392/--- This one does fail, as expected, in Perl. It needs the complex item at the
393     end of the pattern. A single letter instead of (B|D) makes it not fail,
394     which I think is a Perl bug. --- /
395
396/A(*COMMIT)(B|D)/
397    ACABX
398
399/--- Check the use of names for failure ---/
400
401/^(A(*PRUNE:A)B|C(*PRUNE:B)D)/K
402    ** Failers
403    AC
404    CB
405
406/(*MARK:A)(*SKIP:B)(C|X)/K
407    C
408    D
409
410/^(A(*THEN:A)B|C(*THEN:B)D)/K
411    ** Failers
412    CB
413
414/^(?:A(*THEN:A)B|C(*THEN:B)D)/K
415    CB
416
417/^(?>A(*THEN:A)B|C(*THEN:B)D)/K
418    CB
419
420/--- This should succeed, as the skip causes bump to offset 1 (the mark). Note
421that we have to have something complicated such as (B|Z) at the end because,
422for Perl, a simple character somehow causes an unwanted optimization to mess
423with the handling of backtracking verbs. ---/
424
425/A(*MARK:A)A+(*SKIP:A)(B|Z) | AC/xK
426    AAAC
427
428/--- Test skipping over a non-matching mark. ---/
429
430/A(*MARK:A)A+(*MARK:B)(*SKIP:A)(B|Z) | AC/xK
431    AAAC
432
433/--- Check shorthand for MARK ---/
434
435/A(*:A)A+(*SKIP:A)(B|Z) | AC/xK
436    AAAC
437
438/--- Don't loop! ---/
439
440/(*:A)A+(*SKIP:A)(B|Z)/K
441    AAAC
442
443/--- This should succeed, as a non-existent skip name disables the skip ---/
444
445/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/xK
446    AAAC
447
448/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC(*:B)/xK
449    AAAC
450
451/--- We use something more complicated than individual letters here, because
452that causes different behaviour in Perl. Perhaps it disables some optimization;
453anyway, the result now matches PCRE in that no tag is passed back for the
454failures. ---/
455
456/(A|P)(*:A)(B|P) | (X|P)(X|P)(*:B)(Y|P)/xK
457    AABC
458    XXYZ
459    ** Failers
460    XAQQ
461    XAQQXZZ
462    AXQQQ
463    AXXQQQ
464
465/--- COMMIT at the start of a pattern should act like an anchor. Again,
466however, we need the complication for Perl. ---/
467
468/(*COMMIT)(A|P)(B|P)(C|P)/
469    ABCDEFG
470    ** Failers
471    DEFGABC
472
473/--- COMMIT inside an atomic group can't stop backtracking over the group. ---/
474
475/(\w+)(?>b(*COMMIT))\w{2}/
476    abbb
477
478/(\w+)b(*COMMIT)\w{2}/
479    abbb
480
481/--- Check opening parens in comment when seeking forward reference. ---/
482
483/(?&t)(?#()(?(DEFINE)(?<t>a))/
484    bac
485
486/--- COMMIT should override THEN ---/
487
488/(?>(*COMMIT)(?>yes|no)(*THEN)(*F))?/
489  yes
490
491/(?>(*COMMIT)(yes|no)(*THEN)(*F))?/
492  yes
493
494/^((yes|no)(*THEN)(*F))?/
495  yes
496
497/b?(*SKIP)c/
498    bc
499    abc
500
501/(*SKIP)bc/
502    a
503
504/(*SKIP)b/
505    a
506
507/(?P<abn>(?P=abn)xxx|)+/
508    xxx
509
510/-- End of testinput11 --/
511