xref: /aosp_15_r20/external/pcre/testdata/testinput1 (revision 22dc650d8ae982c6770746019a6f94af92b0f024)
1# This set of tests is for features that are compatible with all versions of
2# Perl >= 5.10, in non-UTF mode. It should run clean for the 8-bit, 16-bit, and
3# 32-bit PCRE libraries, and also using the perltest.sh script.
4
5# WARNING: Use only / as the pattern delimiter. Although pcre2test supports
6# a number of delimiters, all those other than / give problems with the
7# perltest.sh script.
8
9#forbid_utf
10#newline_default lf any anycrlf
11#perltest
12
13/the quick brown fox/
14    the quick brown fox
15    What do you know about the quick brown fox?
16\= Expect no match
17    The quick brown FOX
18    What do you know about THE QUICK BROWN FOX?
19
20/The quick brown fox/i
21    the quick brown fox
22    The quick brown FOX
23    What do you know about the quick brown fox?
24    What do you know about THE QUICK BROWN FOX?
25
26/abcd\t\n\r\f\a\e\071\x3b\$\\\?caxyz/
27    abcd\t\n\r\f\a\e9;\$\\?caxyz
28
29/a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz/
30    abxyzpqrrrabbxyyyypqAzz
31    abxyzpqrrrabbxyyyypqAzz
32    aabxyzpqrrrabbxyyyypqAzz
33    aaabxyzpqrrrabbxyyyypqAzz
34    aaaabxyzpqrrrabbxyyyypqAzz
35    abcxyzpqrrrabbxyyyypqAzz
36    aabcxyzpqrrrabbxyyyypqAzz
37    aaabcxyzpqrrrabbxyyyypAzz
38    aaabcxyzpqrrrabbxyyyypqAzz
39    aaabcxyzpqrrrabbxyyyypqqAzz
40    aaabcxyzpqrrrabbxyyyypqqqAzz
41    aaabcxyzpqrrrabbxyyyypqqqqAzz
42    aaabcxyzpqrrrabbxyyyypqqqqqAzz
43    aaabcxyzpqrrrabbxyyyypqqqqqqAzz
44    aaaabcxyzpqrrrabbxyyyypqAzz
45    abxyzzpqrrrabbxyyyypqAzz
46    aabxyzzzpqrrrabbxyyyypqAzz
47    aaabxyzzzzpqrrrabbxyyyypqAzz
48    aaaabxyzzzzpqrrrabbxyyyypqAzz
49    abcxyzzpqrrrabbxyyyypqAzz
50    aabcxyzzzpqrrrabbxyyyypqAzz
51    aaabcxyzzzzpqrrrabbxyyyypqAzz
52    aaaabcxyzzzzpqrrrabbxyyyypqAzz
53    aaaabcxyzzzzpqrrrabbbxyyyypqAzz
54    aaaabcxyzzzzpqrrrabbbxyyyyypqAzz
55    aaabcxyzpqrrrabbxyyyypABzz
56    aaabcxyzpqrrrabbxyyyypABBzz
57    >>>aaabxyzpqrrrabbxyyyypqAzz
58    >aaaabxyzpqrrrabbxyyyypqAzz
59    >>>>abcxyzpqrrrabbxyyyypqAzz
60\= Expect no match
61    abxyzpqrrabbxyyyypqAzz
62    abxyzpqrrrrabbxyyyypqAzz
63    abxyzpqrrrabxyyyypqAzz
64    aaaabcxyzzzzpqrrrabbbxyyyyyypqAzz
65    aaaabcxyzzzzpqrrrabbbxyyypqAzz
66    aaabcxyzpqrrrabbxyyyypqqqqqqqAzz
67
68/^(abc){1,2}zz/
69    abczz
70    abcabczz
71\= Expect no match
72    zz
73    abcabcabczz
74    >>abczz
75
76/^(b+?|a){1,2}?c/
77    bc
78    bbc
79    bbbc
80    bac
81    bbac
82    aac
83    abbbbbbbbbbbc
84    bbbbbbbbbbbac
85\= Expect no match
86    aaac
87    abbbbbbbbbbbac
88
89/^(b+|a){1,2}c/
90    bc
91    bbc
92    bbbc
93    bac
94    bbac
95    aac
96    abbbbbbbbbbbc
97    bbbbbbbbbbbac
98\= Expect no match
99    aaac
100    abbbbbbbbbbbac
101
102/^(ba|b*){1,2}?bc/
103    babc
104    bbabc
105    bababc
106\= Expect no match
107    bababbc
108    babababc
109
110/^\ca\cA\c[;\c:/
111    \x01\x01\e;z
112
113/^[ab\]cde]/
114    athing
115    bthing
116    ]thing
117    cthing
118    dthing
119    ething
120\= Expect no match
121    fthing
122    [thing
123    \\thing
124
125/^[]cde]/
126    ]thing
127    cthing
128    dthing
129    ething
130\= Expect no match
131    athing
132    fthing
133
134/^[^ab\]cde]/
135    fthing
136    [thing
137    \\thing
138\= Expect no match
139    athing
140    bthing
141    ]thing
142    cthing
143    dthing
144    ething
145
146/^[^]cde]/
147    athing
148    fthing
149\= Expect no match
150    ]thing
151    cthing
152    dthing
153    ething
154
155/^\�/
156157
158/^�/
159160
161/^[0-9]+$/
162    0
163    1
164    2
165    3
166    4
167    5
168    6
169    7
170    8
171    9
172    10
173    100
174\= Expect no match
175    abc
176
177/^.*nter/
178    enter
179    inter
180    uponter
181
182/^xxx[0-9]+$/
183    xxx0
184    xxx1234
185\= Expect no match
186    xxx
187
188/^.+[0-9][0-9][0-9]$/
189    x123
190    x1234
191    xx123
192    123456
193\= Expect no match
194    123
195
196/^.+?[0-9][0-9][0-9]$/
197    x123
198    x1234
199    xx123
200    123456
201\= Expect no match
202    123
203
204/^([^!]+)!(.+)=apquxz\.ixr\.zzz\.ac\.uk$/
205    abc!pqr=apquxz.ixr.zzz.ac.uk
206\= Expect no match
207    !pqr=apquxz.ixr.zzz.ac.uk
208    abc!=apquxz.ixr.zzz.ac.uk
209    abc!pqr=apquxz:ixr.zzz.ac.uk
210    abc!pqr=apquxz.ixr.zzz.ac.ukk
211
212/:/
213    Well, we need a colon: somewhere
214\= Expect no match
215    Fail without a colon
216
217/([\da-f:]+)$/i
218    0abc
219    abc
220    fed
221    E
222    ::
223    5f03:12C0::932e
224    fed def
225    Any old stuff
226\= Expect no match
227    0zzz
228    gzzz
229    fed\x20
230    Any old rubbish
231
232/^.*\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
233    .1.2.3
234    A.12.123.0
235\= Expect no match
236    .1.2.3333
237    1.2.3
238    1234.2.3
239
240/^(\d+)\s+IN\s+SOA\s+(\S+)\s+(\S+)\s*\(\s*$/
241    1 IN SOA non-sp1 non-sp2(
242    1    IN    SOA    non-sp1    non-sp2   (
243\= Expect no match
244    1IN SOA non-sp1 non-sp2(
245
246/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-z\d\-]*)*\.$/
247    a.
248    Z.
249    2.
250    ab-c.pq-r.
251    sxk.zzz.ac.uk.
252    x-.y-.
253\= Expect no match
254    -abc.peq.
255
256/^\*\.[a-z]([a-z\-\d]*[a-z\d]+)?(\.[a-z]([a-z\-\d]*[a-z\d]+)?)*$/
257    *.a
258    *.b0-a
259    *.c3-b.c
260    *.c-a.b-c
261\= Expect no match
262    *.0
263    *.a-
264    *.a-b.c-
265    *.c-a.0-c
266
267/^(?=ab(de))(abd)(e)/
268    abde
269
270/^(?!(ab)de|x)(abd)(f)/
271    abdf
272
273/^(?=(ab(cd)))(ab)/
274    abcd
275
276/^[\da-f](\.[\da-f])*$/i
277    a.b.c.d
278    A.B.C.D
279    a.b.c.1.2.3.C
280
281/^\".*\"\s*(;.*)?$/
282    \"1234\"
283    \"abcd\" ;
284    \"\" ; rhubarb
285\= Expect no match
286    \"1234\" : things
287
288/^$/
289    \
290\= Expect no match
291    A non-empty line
292
293/   ^    a   (?# begins with a)  b\sc (?# then b c) $ (?# then end)/x
294    ab c
295\= Expect no match
296    abc
297    ab cde
298
299/(?x)   ^    a   (?# begins with a)  b\sc (?# then b c) $ (?# then end)/
300    ab c
301\= Expect no match
302    abc
303    ab cde
304
305/^   a\ b[c ]d       $/x
306    a bcd
307    a b d
308\= Expect no match
309    abcd
310    ab d
311
312/^(a(b(c)))(d(e(f)))(h(i(j)))(k(l(m)))$/
313    abcdefhijklm
314
315/^(?:a(b(c)))(?:d(e(f)))(?:h(i(j)))(?:k(l(m)))$/
316    abcdefhijklm
317
318/^[\w][\W][\s][\S][\d][\D][\b][\n][\c]][\022]/
319    a+ Z0+\x08\n\x1d\x12
320
321/^[.^$|()*+?{,}]+/
322    .^\$(*+)|{?,?}
323
324/^a*\w/
325    z
326    az
327    aaaz
328    a
329    aa
330    aaaa
331    a+
332    aa+
333
334/^a*?\w/
335    z
336    az
337    aaaz
338    a
339    aa
340    aaaa
341    a+
342    aa+
343
344/^a+\w/
345    az
346    aaaz
347    aa
348    aaaa
349    aa+
350
351/^a+?\w/
352    az
353    aaaz
354    aa
355    aaaa
356    aa+
357
358/^\d{8}\w{2,}/
359    1234567890
360    12345678ab
361    12345678__
362\= Expect no match
363    1234567
364
365/^[aeiou\d]{4,5}$/
366    uoie
367    1234
368    12345
369    aaaaa
370\= Expect no match
371    123456
372
373/^[aeiou\d]{4,5}?/
374    uoie
375    1234
376    12345
377    aaaaa
378    123456
379
380/\A(abc|def)=(\1){2,3}\Z/
381    abc=abcabc
382    def=defdefdef
383\= Expect no match
384    abc=defdef
385
386/^(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\11*(\3\4)\1(?#)2$/
387    abcdefghijkcda2
388    abcdefghijkkkkcda2
389
390/(cat(a(ract|tonic)|erpillar)) \1()2(3)/
391    cataract cataract23
392    catatonic catatonic23
393    caterpillar caterpillar23
394
395
396/^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/
397    From abcd  Mon Sep 01 12:33:02 1997
398
399/^From\s+\S+\s+([a-zA-Z]{3}\s+){2}\d{1,2}\s+\d\d:\d\d/
400    From abcd  Mon Sep 01 12:33:02 1997
401    From abcd  Mon Sep  1 12:33:02 1997
402\= Expect no match
403    From abcd  Sep 01 12:33:02 1997
404
405/^12.34/s
406    12\n34
407    12\r34
408
409/\w+(?=\t)/
410    the quick brown\t fox
411
412/foo(?!bar)(.*)/
413    foobar is foolish see?
414
415/(?:(?!foo)...|^.{0,2})bar(.*)/
416    foobar crowbar etc
417    barrel
418    2barrel
419    A barrel
420
421/^(\D*)(?=\d)(?!123)/
422    abc456
423\= Expect no match
424    abc123
425
426/^1234(?# test newlines
427  inside)/
428    1234
429
430/^1234 #comment in extended re
431  /x
432    1234
433
434/#rhubarb
435  abcd/x
436    abcd
437
438/^abcd#rhubarb/x
439    abcd
440
441/^(a)\1{2,3}(.)/
442    aaab
443    aaaab
444    aaaaab
445    aaaaaab
446
447/(?!^)abc/
448    the abc
449\= Expect no match
450    abc
451
452/(?=^)abc/
453    abc
454\= Expect no match
455    the abc
456
457/^[ab]{1,3}(ab*|b)/
458    aabbbbb
459
460/^[ab]{1,3}?(ab*|b)/
461    aabbbbb
462
463/^[ab]{1,3}?(ab*?|b)/
464    aabbbbb
465
466/^[ab]{1,3}(ab*?|b)/
467    aabbbbb
468
469/  (?: [\040\t] |  \(
470(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
471\)  )*                          # optional leading comment
472(?:    (?:
473[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
474(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
475|
476" (?:                      # opening quote...
477[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
478|                     #    or
479\\ [^\x80-\xff]           #   Escaped something (something != CR)
480)* "  # closing quote
481)                    # initial word
482(?:  (?: [\040\t] |  \(
483(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
484\)  )*  \.  (?: [\040\t] |  \(
485(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
486\)  )*   (?:
487[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
488(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
489|
490" (?:                      # opening quote...
491[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
492|                     #    or
493\\ [^\x80-\xff]           #   Escaped something (something != CR)
494)* "  # closing quote
495)  )* # further okay, if led by a period
496(?: [\040\t] |  \(
497(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
498\)  )*  @  (?: [\040\t] |  \(
499(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
500\)  )*    (?:
501[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
502(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
503|   \[                         # [
504(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
505\]                        #           ]
506)                           # initial subdomain
507(?:                                  #
508(?: [\040\t] |  \(
509(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
510\)  )*  \.                        # if led by a period...
511(?: [\040\t] |  \(
512(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
513\)  )*   (?:
514[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
515(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
516|   \[                         # [
517(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
518\]                        #           ]
519)                     #   ...further okay
520)*
521# address
522|                     #  or
523(?:
524[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
525(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
526|
527" (?:                      # opening quote...
528[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
529|                     #    or
530\\ [^\x80-\xff]           #   Escaped something (something != CR)
531)* "  # closing quote
532)             # one word, optionally followed by....
533(?:
534[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]  |  # atom and space parts, or...
535\(
536(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
537\)       |  # comments, or...
538
539" (?:                      # opening quote...
540[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
541|                     #    or
542\\ [^\x80-\xff]           #   Escaped something (something != CR)
543)* "  # closing quote
544# quoted strings
545)*
546<  (?: [\040\t] |  \(
547(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
548\)  )*                     # leading <
549(?:  @  (?: [\040\t] |  \(
550(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
551\)  )*    (?:
552[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
553(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
554|   \[                         # [
555(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
556\]                        #           ]
557)                           # initial subdomain
558(?:                                  #
559(?: [\040\t] |  \(
560(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
561\)  )*  \.                        # if led by a period...
562(?: [\040\t] |  \(
563(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
564\)  )*   (?:
565[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
566(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
567|   \[                         # [
568(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
569\]                        #           ]
570)                     #   ...further okay
571)*
572
573(?:  (?: [\040\t] |  \(
574(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
575\)  )*  ,  (?: [\040\t] |  \(
576(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
577\)  )*  @  (?: [\040\t] |  \(
578(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
579\)  )*    (?:
580[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
581(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
582|   \[                         # [
583(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
584\]                        #           ]
585)                           # initial subdomain
586(?:                                  #
587(?: [\040\t] |  \(
588(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
589\)  )*  \.                        # if led by a period...
590(?: [\040\t] |  \(
591(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
592\)  )*   (?:
593[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
594(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
595|   \[                         # [
596(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
597\]                        #           ]
598)                     #   ...further okay
599)*
600)* # further okay, if led by comma
601:                                # closing colon
602(?: [\040\t] |  \(
603(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
604\)  )*  )? #       optional route
605(?:
606[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
607(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
608|
609" (?:                      # opening quote...
610[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
611|                     #    or
612\\ [^\x80-\xff]           #   Escaped something (something != CR)
613)* "  # closing quote
614)                    # initial word
615(?:  (?: [\040\t] |  \(
616(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
617\)  )*  \.  (?: [\040\t] |  \(
618(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
619\)  )*   (?:
620[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
621(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
622|
623" (?:                      # opening quote...
624[^\\\x80-\xff\n\015"]                #   Anything except backslash and quote
625|                     #    or
626\\ [^\x80-\xff]           #   Escaped something (something != CR)
627)* "  # closing quote
628)  )* # further okay, if led by a period
629(?: [\040\t] |  \(
630(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
631\)  )*  @  (?: [\040\t] |  \(
632(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
633\)  )*    (?:
634[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
635(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
636|   \[                         # [
637(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
638\]                        #           ]
639)                           # initial subdomain
640(?:                                  #
641(?: [\040\t] |  \(
642(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
643\)  )*  \.                        # if led by a period...
644(?: [\040\t] |  \(
645(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
646\)  )*   (?:
647[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
648(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
649|   \[                         # [
650(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*    #    stuff
651\]                        #           ]
652)                     #   ...further okay
653)*
654#       address spec
655(?: [\040\t] |  \(
656(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
657\)  )*  > #                  trailing >
658# name and address
659)  (?: [\040\t] |  \(
660(?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  |  \( (?:  [^\\\x80-\xff\n\015()]  |  \\ [^\x80-\xff]  )* \)  )*
661\)  )*                       # optional trailing comment
662/x
663    Alan Other <user\@dom.ain>
664    <user\@dom.ain>
665    user\@dom.ain
666    \"A. Other\" <user.1234\@dom.ain> (a comment)
667    A. Other <user.1234\@dom.ain> (a comment)
668    \"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"\@x400-re.lay
669    A missing angle <user\@some.where
670\= Expect no match
671    The quick brown fox
672
673/[\040\t]*                    # Nab whitespace.
674(?:
675\(                              #  (
676[^\\\x80-\xff\n\015()] *                             #     normal*
677(?:                                 #       (
678(?:  \\ [^\x80-\xff]  |
679\(                            #  (
680[^\\\x80-\xff\n\015()] *                            #     normal*
681(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
682\)                           #                       )
683)    #         special
684[^\\\x80-\xff\n\015()] *                         #         normal*
685)*                                  #            )*
686\)                             #                )
687[\040\t]* )*    # If comment found, allow more spaces.
688# optional leading comment
689(?:
690(?:
691[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
692(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
693# Atom
694|                       #  or
695"                                     # "
696[^\\\x80-\xff\n\015"] *                            #   normal
697(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
698"                                     #        "
699# Quoted string
700)
701[\040\t]*                    # Nab whitespace.
702(?:
703\(                              #  (
704[^\\\x80-\xff\n\015()] *                             #     normal*
705(?:                                 #       (
706(?:  \\ [^\x80-\xff]  |
707\(                            #  (
708[^\\\x80-\xff\n\015()] *                            #     normal*
709(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
710\)                           #                       )
711)    #         special
712[^\\\x80-\xff\n\015()] *                         #         normal*
713)*                                  #            )*
714\)                             #                )
715[\040\t]* )*    # If comment found, allow more spaces.
716(?:
717\.
718[\040\t]*                    # Nab whitespace.
719(?:
720\(                              #  (
721[^\\\x80-\xff\n\015()] *                             #     normal*
722(?:                                 #       (
723(?:  \\ [^\x80-\xff]  |
724\(                            #  (
725[^\\\x80-\xff\n\015()] *                            #     normal*
726(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
727\)                           #                       )
728)    #         special
729[^\\\x80-\xff\n\015()] *                         #         normal*
730)*                                  #            )*
731\)                             #                )
732[\040\t]* )*    # If comment found, allow more spaces.
733(?:
734[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
735(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
736# Atom
737|                       #  or
738"                                     # "
739[^\\\x80-\xff\n\015"] *                            #   normal
740(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
741"                                     #        "
742# Quoted string
743)
744[\040\t]*                    # Nab whitespace.
745(?:
746\(                              #  (
747[^\\\x80-\xff\n\015()] *                             #     normal*
748(?:                                 #       (
749(?:  \\ [^\x80-\xff]  |
750\(                            #  (
751[^\\\x80-\xff\n\015()] *                            #     normal*
752(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
753\)                           #                       )
754)    #         special
755[^\\\x80-\xff\n\015()] *                         #         normal*
756)*                                  #            )*
757\)                             #                )
758[\040\t]* )*    # If comment found, allow more spaces.
759# additional words
760)*
761@
762[\040\t]*                    # Nab whitespace.
763(?:
764\(                              #  (
765[^\\\x80-\xff\n\015()] *                             #     normal*
766(?:                                 #       (
767(?:  \\ [^\x80-\xff]  |
768\(                            #  (
769[^\\\x80-\xff\n\015()] *                            #     normal*
770(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
771\)                           #                       )
772)    #         special
773[^\\\x80-\xff\n\015()] *                         #         normal*
774)*                                  #            )*
775\)                             #                )
776[\040\t]* )*    # If comment found, allow more spaces.
777(?:
778[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
779(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
780|
781\[                            # [
782(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
783\]                           #           ]
784)
785[\040\t]*                    # Nab whitespace.
786(?:
787\(                              #  (
788[^\\\x80-\xff\n\015()] *                             #     normal*
789(?:                                 #       (
790(?:  \\ [^\x80-\xff]  |
791\(                            #  (
792[^\\\x80-\xff\n\015()] *                            #     normal*
793(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
794\)                           #                       )
795)    #         special
796[^\\\x80-\xff\n\015()] *                         #         normal*
797)*                                  #            )*
798\)                             #                )
799[\040\t]* )*    # If comment found, allow more spaces.
800# optional trailing comments
801(?:
802\.
803[\040\t]*                    # Nab whitespace.
804(?:
805\(                              #  (
806[^\\\x80-\xff\n\015()] *                             #     normal*
807(?:                                 #       (
808(?:  \\ [^\x80-\xff]  |
809\(                            #  (
810[^\\\x80-\xff\n\015()] *                            #     normal*
811(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
812\)                           #                       )
813)    #         special
814[^\\\x80-\xff\n\015()] *                         #         normal*
815)*                                  #            )*
816\)                             #                )
817[\040\t]* )*    # If comment found, allow more spaces.
818(?:
819[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
820(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
821|
822\[                            # [
823(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
824\]                           #           ]
825)
826[\040\t]*                    # Nab whitespace.
827(?:
828\(                              #  (
829[^\\\x80-\xff\n\015()] *                             #     normal*
830(?:                                 #       (
831(?:  \\ [^\x80-\xff]  |
832\(                            #  (
833[^\\\x80-\xff\n\015()] *                            #     normal*
834(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
835\)                           #                       )
836)    #         special
837[^\\\x80-\xff\n\015()] *                         #         normal*
838)*                                  #            )*
839\)                             #                )
840[\040\t]* )*    # If comment found, allow more spaces.
841# optional trailing comments
842)*
843# address
844|                             #  or
845(?:
846[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
847(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
848# Atom
849|                       #  or
850"                                     # "
851[^\\\x80-\xff\n\015"] *                            #   normal
852(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
853"                                     #        "
854# Quoted string
855)
856# leading word
857[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037] *               # "normal" atoms and or spaces
858(?:
859(?:
860\(                              #  (
861[^\\\x80-\xff\n\015()] *                             #     normal*
862(?:                                 #       (
863(?:  \\ [^\x80-\xff]  |
864\(                            #  (
865[^\\\x80-\xff\n\015()] *                            #     normal*
866(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
867\)                           #                       )
868)    #         special
869[^\\\x80-\xff\n\015()] *                         #         normal*
870)*                                  #            )*
871\)                             #                )
872|
873"                                     # "
874[^\\\x80-\xff\n\015"] *                            #   normal
875(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
876"                                     #        "
877) # "special" comment or quoted string
878[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037] *            #  more "normal"
879)*
880<
881[\040\t]*                    # Nab whitespace.
882(?:
883\(                              #  (
884[^\\\x80-\xff\n\015()] *                             #     normal*
885(?:                                 #       (
886(?:  \\ [^\x80-\xff]  |
887\(                            #  (
888[^\\\x80-\xff\n\015()] *                            #     normal*
889(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
890\)                           #                       )
891)    #         special
892[^\\\x80-\xff\n\015()] *                         #         normal*
893)*                                  #            )*
894\)                             #                )
895[\040\t]* )*    # If comment found, allow more spaces.
896# <
897(?:
898@
899[\040\t]*                    # Nab whitespace.
900(?:
901\(                              #  (
902[^\\\x80-\xff\n\015()] *                             #     normal*
903(?:                                 #       (
904(?:  \\ [^\x80-\xff]  |
905\(                            #  (
906[^\\\x80-\xff\n\015()] *                            #     normal*
907(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
908\)                           #                       )
909)    #         special
910[^\\\x80-\xff\n\015()] *                         #         normal*
911)*                                  #            )*
912\)                             #                )
913[\040\t]* )*    # If comment found, allow more spaces.
914(?:
915[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
916(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
917|
918\[                            # [
919(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
920\]                           #           ]
921)
922[\040\t]*                    # Nab whitespace.
923(?:
924\(                              #  (
925[^\\\x80-\xff\n\015()] *                             #     normal*
926(?:                                 #       (
927(?:  \\ [^\x80-\xff]  |
928\(                            #  (
929[^\\\x80-\xff\n\015()] *                            #     normal*
930(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
931\)                           #                       )
932)    #         special
933[^\\\x80-\xff\n\015()] *                         #         normal*
934)*                                  #            )*
935\)                             #                )
936[\040\t]* )*    # If comment found, allow more spaces.
937# optional trailing comments
938(?:
939\.
940[\040\t]*                    # Nab whitespace.
941(?:
942\(                              #  (
943[^\\\x80-\xff\n\015()] *                             #     normal*
944(?:                                 #       (
945(?:  \\ [^\x80-\xff]  |
946\(                            #  (
947[^\\\x80-\xff\n\015()] *                            #     normal*
948(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
949\)                           #                       )
950)    #         special
951[^\\\x80-\xff\n\015()] *                         #         normal*
952)*                                  #            )*
953\)                             #                )
954[\040\t]* )*    # If comment found, allow more spaces.
955(?:
956[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
957(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
958|
959\[                            # [
960(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
961\]                           #           ]
962)
963[\040\t]*                    # Nab whitespace.
964(?:
965\(                              #  (
966[^\\\x80-\xff\n\015()] *                             #     normal*
967(?:                                 #       (
968(?:  \\ [^\x80-\xff]  |
969\(                            #  (
970[^\\\x80-\xff\n\015()] *                            #     normal*
971(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
972\)                           #                       )
973)    #         special
974[^\\\x80-\xff\n\015()] *                         #         normal*
975)*                                  #            )*
976\)                             #                )
977[\040\t]* )*    # If comment found, allow more spaces.
978# optional trailing comments
979)*
980(?: ,
981[\040\t]*                    # Nab whitespace.
982(?:
983\(                              #  (
984[^\\\x80-\xff\n\015()] *                             #     normal*
985(?:                                 #       (
986(?:  \\ [^\x80-\xff]  |
987\(                            #  (
988[^\\\x80-\xff\n\015()] *                            #     normal*
989(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
990\)                           #                       )
991)    #         special
992[^\\\x80-\xff\n\015()] *                         #         normal*
993)*                                  #            )*
994\)                             #                )
995[\040\t]* )*    # If comment found, allow more spaces.
996@
997[\040\t]*                    # Nab whitespace.
998(?:
999\(                              #  (
1000[^\\\x80-\xff\n\015()] *                             #     normal*
1001(?:                                 #       (
1002(?:  \\ [^\x80-\xff]  |
1003\(                            #  (
1004[^\\\x80-\xff\n\015()] *                            #     normal*
1005(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1006\)                           #                       )
1007)    #         special
1008[^\\\x80-\xff\n\015()] *                         #         normal*
1009)*                                  #            )*
1010\)                             #                )
1011[\040\t]* )*    # If comment found, allow more spaces.
1012(?:
1013[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1014(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1015|
1016\[                            # [
1017(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
1018\]                           #           ]
1019)
1020[\040\t]*                    # Nab whitespace.
1021(?:
1022\(                              #  (
1023[^\\\x80-\xff\n\015()] *                             #     normal*
1024(?:                                 #       (
1025(?:  \\ [^\x80-\xff]  |
1026\(                            #  (
1027[^\\\x80-\xff\n\015()] *                            #     normal*
1028(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1029\)                           #                       )
1030)    #         special
1031[^\\\x80-\xff\n\015()] *                         #         normal*
1032)*                                  #            )*
1033\)                             #                )
1034[\040\t]* )*    # If comment found, allow more spaces.
1035# optional trailing comments
1036(?:
1037\.
1038[\040\t]*                    # Nab whitespace.
1039(?:
1040\(                              #  (
1041[^\\\x80-\xff\n\015()] *                             #     normal*
1042(?:                                 #       (
1043(?:  \\ [^\x80-\xff]  |
1044\(                            #  (
1045[^\\\x80-\xff\n\015()] *                            #     normal*
1046(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1047\)                           #                       )
1048)    #         special
1049[^\\\x80-\xff\n\015()] *                         #         normal*
1050)*                                  #            )*
1051\)                             #                )
1052[\040\t]* )*    # If comment found, allow more spaces.
1053(?:
1054[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1055(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1056|
1057\[                            # [
1058(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
1059\]                           #           ]
1060)
1061[\040\t]*                    # Nab whitespace.
1062(?:
1063\(                              #  (
1064[^\\\x80-\xff\n\015()] *                             #     normal*
1065(?:                                 #       (
1066(?:  \\ [^\x80-\xff]  |
1067\(                            #  (
1068[^\\\x80-\xff\n\015()] *                            #     normal*
1069(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1070\)                           #                       )
1071)    #         special
1072[^\\\x80-\xff\n\015()] *                         #         normal*
1073)*                                  #            )*
1074\)                             #                )
1075[\040\t]* )*    # If comment found, allow more spaces.
1076# optional trailing comments
1077)*
1078)*  # additional domains
1079:
1080[\040\t]*                    # Nab whitespace.
1081(?:
1082\(                              #  (
1083[^\\\x80-\xff\n\015()] *                             #     normal*
1084(?:                                 #       (
1085(?:  \\ [^\x80-\xff]  |
1086\(                            #  (
1087[^\\\x80-\xff\n\015()] *                            #     normal*
1088(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1089\)                           #                       )
1090)    #         special
1091[^\\\x80-\xff\n\015()] *                         #         normal*
1092)*                                  #            )*
1093\)                             #                )
1094[\040\t]* )*    # If comment found, allow more spaces.
1095# optional trailing comments
1096)?     #       optional route
1097(?:
1098[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1099(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1100# Atom
1101|                       #  or
1102"                                     # "
1103[^\\\x80-\xff\n\015"] *                            #   normal
1104(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
1105"                                     #        "
1106# Quoted string
1107)
1108[\040\t]*                    # Nab whitespace.
1109(?:
1110\(                              #  (
1111[^\\\x80-\xff\n\015()] *                             #     normal*
1112(?:                                 #       (
1113(?:  \\ [^\x80-\xff]  |
1114\(                            #  (
1115[^\\\x80-\xff\n\015()] *                            #     normal*
1116(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1117\)                           #                       )
1118)    #         special
1119[^\\\x80-\xff\n\015()] *                         #         normal*
1120)*                                  #            )*
1121\)                             #                )
1122[\040\t]* )*    # If comment found, allow more spaces.
1123(?:
1124\.
1125[\040\t]*                    # Nab whitespace.
1126(?:
1127\(                              #  (
1128[^\\\x80-\xff\n\015()] *                             #     normal*
1129(?:                                 #       (
1130(?:  \\ [^\x80-\xff]  |
1131\(                            #  (
1132[^\\\x80-\xff\n\015()] *                            #     normal*
1133(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1134\)                           #                       )
1135)    #         special
1136[^\\\x80-\xff\n\015()] *                         #         normal*
1137)*                                  #            )*
1138\)                             #                )
1139[\040\t]* )*    # If comment found, allow more spaces.
1140(?:
1141[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1142(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1143# Atom
1144|                       #  or
1145"                                     # "
1146[^\\\x80-\xff\n\015"] *                            #   normal
1147(?:  \\ [^\x80-\xff]  [^\\\x80-\xff\n\015"] * )*        #   ( special normal* )*
1148"                                     #        "
1149# Quoted string
1150)
1151[\040\t]*                    # Nab whitespace.
1152(?:
1153\(                              #  (
1154[^\\\x80-\xff\n\015()] *                             #     normal*
1155(?:                                 #       (
1156(?:  \\ [^\x80-\xff]  |
1157\(                            #  (
1158[^\\\x80-\xff\n\015()] *                            #     normal*
1159(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1160\)                           #                       )
1161)    #         special
1162[^\\\x80-\xff\n\015()] *                         #         normal*
1163)*                                  #            )*
1164\)                             #                )
1165[\040\t]* )*    # If comment found, allow more spaces.
1166# additional words
1167)*
1168@
1169[\040\t]*                    # Nab whitespace.
1170(?:
1171\(                              #  (
1172[^\\\x80-\xff\n\015()] *                             #     normal*
1173(?:                                 #       (
1174(?:  \\ [^\x80-\xff]  |
1175\(                            #  (
1176[^\\\x80-\xff\n\015()] *                            #     normal*
1177(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1178\)                           #                       )
1179)    #         special
1180[^\\\x80-\xff\n\015()] *                         #         normal*
1181)*                                  #            )*
1182\)                             #                )
1183[\040\t]* )*    # If comment found, allow more spaces.
1184(?:
1185[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1186(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1187|
1188\[                            # [
1189(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
1190\]                           #           ]
1191)
1192[\040\t]*                    # Nab whitespace.
1193(?:
1194\(                              #  (
1195[^\\\x80-\xff\n\015()] *                             #     normal*
1196(?:                                 #       (
1197(?:  \\ [^\x80-\xff]  |
1198\(                            #  (
1199[^\\\x80-\xff\n\015()] *                            #     normal*
1200(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1201\)                           #                       )
1202)    #         special
1203[^\\\x80-\xff\n\015()] *                         #         normal*
1204)*                                  #            )*
1205\)                             #                )
1206[\040\t]* )*    # If comment found, allow more spaces.
1207# optional trailing comments
1208(?:
1209\.
1210[\040\t]*                    # Nab whitespace.
1211(?:
1212\(                              #  (
1213[^\\\x80-\xff\n\015()] *                             #     normal*
1214(?:                                 #       (
1215(?:  \\ [^\x80-\xff]  |
1216\(                            #  (
1217[^\\\x80-\xff\n\015()] *                            #     normal*
1218(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1219\)                           #                       )
1220)    #         special
1221[^\\\x80-\xff\n\015()] *                         #         normal*
1222)*                                  #            )*
1223\)                             #                )
1224[\040\t]* )*    # If comment found, allow more spaces.
1225(?:
1226[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+    # some number of atom characters...
1227(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]) # ..not followed by something that could be part of an atom
1228|
1229\[                            # [
1230(?: [^\\\x80-\xff\n\015\[\]] |  \\ [^\x80-\xff]  )*     #    stuff
1231\]                           #           ]
1232)
1233[\040\t]*                    # Nab whitespace.
1234(?:
1235\(                              #  (
1236[^\\\x80-\xff\n\015()] *                             #     normal*
1237(?:                                 #       (
1238(?:  \\ [^\x80-\xff]  |
1239\(                            #  (
1240[^\\\x80-\xff\n\015()] *                            #     normal*
1241(?:  \\ [^\x80-\xff]   [^\\\x80-\xff\n\015()] * )*        #     (special normal*)*
1242\)                           #                       )
1243)    #         special
1244[^\\\x80-\xff\n\015()] *                         #         normal*
1245)*                                  #            )*
1246\)                             #                )
1247[\040\t]* )*    # If comment found, allow more spaces.
1248# optional trailing comments
1249)*
1250#       address spec
1251>                    #                 >
1252# name and address
1253)
1254/x
1255    Alan Other <user\@dom.ain>
1256    <user\@dom.ain>
1257    user\@dom.ain
1258    \"A. Other\" <user.1234\@dom.ain> (a comment)
1259    A. Other <user.1234\@dom.ain> (a comment)
1260    \"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"\@x400-re.lay
1261    A missing angle <user\@some.where
1262\= Expect no match
1263    The quick brown fox
1264
1265/abc\0def\00pqr\000xyz\0000AB/
1266    abc\0def\00pqr\000xyz\0000AB
1267    abc456 abc\0def\00pqr\000xyz\0000ABCDE
1268
1269/abc\x0def\x00pqr\x000xyz\x0000AB/
1270    abc\x0def\x00pqr\x000xyz\x0000AB
1271    abc456 abc\x0def\x00pqr\x000xyz\x0000ABCDE
1272
1273/^[\000-\037]/
1274    \0A
1275    \01B
1276    \037C
1277
1278/\0*/
1279    \0\0\0\0
1280
1281/A\x0{2,3}Z/
1282    The A\x0\x0Z
1283    An A\0\x0\0Z
1284\= Expect no match
1285    A\0Z
1286    A\0\x0\0\x0Z
1287
1288/^(cow|)\1(bell)/
1289    cowcowbell
1290    bell
1291\= Expect no match
1292    cowbell
1293
1294/^\s/
1295    \040abc
1296    \x0cabc
1297    \nabc
1298    \rabc
1299    \tabc
1300\= Expect no match
1301    abc
1302
1303/^a	b
1304      c/x
1305    abc
1306
1307/^(a|)\1*b/
1308    ab
1309    aaaab
1310    b
1311\= Expect no match
1312    acb
1313
1314/^(a|)\1+b/
1315    aab
1316    aaaab
1317    b
1318\= Expect no match
1319    ab
1320
1321/^(a|)\1?b/
1322    ab
1323    aab
1324    b
1325\= Expect no match
1326    acb
1327
1328/^(a|)\1{2}b/
1329    aaab
1330    b
1331\= Expect no match
1332    ab
1333    aab
1334    aaaab
1335
1336/^(a|)\1{2,3}b/
1337    aaab
1338    aaaab
1339    b
1340\= Expect no match
1341    ab
1342    aab
1343    aaaaab
1344
1345/ab{1,3}bc/
1346    abbbbc
1347    abbbc
1348    abbc
1349\= Expect no match
1350    abc
1351    abbbbbc
1352
1353/([^.]*)\.([^:]*):[T ]+(.*)/
1354    track1.title:TBlah blah blah
1355
1356/([^.]*)\.([^:]*):[T ]+(.*)/i
1357    track1.title:TBlah blah blah
1358
1359/([^.]*)\.([^:]*):[t ]+(.*)/i
1360    track1.title:TBlah blah blah
1361
1362/^[W-c]+$/
1363    WXY_^abc
1364\= Expect no match
1365    wxy
1366
1367/^[W-c]+$/i
1368    WXY_^abc
1369    wxy_^ABC
1370
1371/^[\x3f-\x5F]+$/i
1372    WXY_^abc
1373    wxy_^ABC
1374
1375/^abc$/m
1376    abc
1377    qqq\nabc
1378    abc\nzzz
1379    qqq\nabc\nzzz
1380
1381/^abc$/
1382    abc
1383\= Expect no match
1384    qqq\nabc
1385    abc\nzzz
1386    qqq\nabc\nzzz
1387
1388/\Aabc\Z/m
1389    abc
1390    abc\n
1391\= Expect no match
1392    qqq\nabc
1393    abc\nzzz
1394    qqq\nabc\nzzz
1395
1396/\A(.)*\Z/s
1397    abc\ndef
1398
1399/\A(.)*\Z/m
1400\= Expect no match
1401    abc\ndef
1402
1403/(?:b)|(?::+)/
1404    b::c
1405    c::b
1406
1407/[-az]+/
1408    az-
1409\= Expect no match
1410    b
1411
1412/[az-]+/
1413    za-
1414\= Expect no match
1415    b
1416
1417/[a\-z]+/
1418    a-z
1419\= Expect no match
1420    b
1421
1422/[a-z]+/
1423    abcdxyz
1424
1425/[\d-]+/
1426    12-34
1427\= Expect no match
1428    aaa
1429
1430/\x5c/
1431    \\
1432
1433/\x20Z/
1434    the Zoo
1435\= Expect no match
1436    Zulu
1437
1438/(abc)\1/i
1439    abcabc
1440    ABCabc
1441    abcABC
1442
1443/abc$/
1444    abc
1445    abc\n
1446\= Expect no match
1447    abc\ndef
1448
1449/(abc)\123/
1450    abc\x53
1451
1452/(abc)\223/
1453    abc\x93
1454
1455/(abc)\323/
1456    abc\xd3
1457
1458/(abc)\100/
1459    abc\x40
1460    abc\100
1461
1462/(abc)\1000/
1463    abc\x400
1464    abc\x40\x30
1465    abc\1000
1466    abc\100\x30
1467    abc\100\060
1468    abc\100\60
1469
1470/^(A)(B)(C)(D)(E)(F)(G)(H)(I)\8\9$/
1471    ABCDEFGHIHI
1472
1473/^[A\8B\9C]+$/
1474    A8B9C
1475\= Expect no match
1476    A8B9C\x00
1477
1478/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\12\123/
1479    abcdefghijkllS
1480
1481/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/
1482    abcdefghijk\12S
1483
1484/a{0}bc/
1485    bc
1486
1487/(a|(bc)){0,0}?xyz/
1488    xyz
1489
1490/abc[\10]de/
1491    abc\010de
1492
1493/abc[\1]de/
1494    abc\1de
1495
1496/(abc)[\1]de/
1497    abc\1de
1498
1499/(?s)a.b/
1500    a\nb
1501
1502/^([^a])([^\b])([^c]*)([^d]{3,4})/
1503    baNOTccccd
1504    baNOTcccd
1505    baNOTccd
1506    bacccd
1507\= Expect no match
1508    anything
1509    b\bc
1510    baccd
1511
1512/[^a]/
1513    Abc
1514
1515/[^a]/i
1516    Abc
1517
1518/[^a]+/
1519    AAAaAbc
1520
1521/[^a]+/i
1522    AAAaAbc
1523
1524/[^a]+/
1525    bbb\nccc
1526
1527/[^k]$/
1528    abc
1529\= Expect no match
1530    abk
1531
1532/[^k]{2,3}$/
1533    abc
1534    kbc
1535    kabc
1536\= Expect no match
1537    abk
1538    akb
1539    akk
1540
1541/^\d{8,}\@.+[^k]$/
1542    12345678\@a.b.c.d
1543    123456789\@x.y.z
1544\= Expect no match
1545    12345678\@x.y.uk
1546    1234567\@a.b.c.d
1547
1548/(a)\1{8,}/
1549    aaaaaaaaa
1550    aaaaaaaaaa
1551\= Expect no match
1552    aaaaaaa
1553
1554/[^a]/
1555    aaaabcd
1556    aaAabcd
1557
1558/[^a]/i
1559    aaaabcd
1560    aaAabcd
1561
1562/[^az]/
1563    aaaabcd
1564    aaAabcd
1565
1566/[^az]/i
1567    aaaabcd
1568    aaAabcd
1569
1570/\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377/
1571 \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377
1572
1573/P[^*]TAIRE[^*]{1,6}?LL/
1574    xxxxxxxxxxxPSTAIREISLLxxxxxxxxx
1575
1576/P[^*]TAIRE[^*]{1,}?LL/
1577    xxxxxxxxxxxPSTAIREISLLxxxxxxxxx
1578
1579/(\.\d\d[1-9]?)\d+/
1580    1.230003938
1581    1.875000282
1582    1.235
1583
1584/(\.\d\d((?=0)|\d(?=\d)))/
1585    1.230003938
1586    1.875000282
1587\= Expect no match
1588    1.235
1589
1590/a(?)b/
1591    ab
1592
1593/\b(foo)\s+(\w+)/i
1594    Food is on the foo table
1595
1596/foo(.*)bar/
1597    The food is under the bar in the barn.
1598
1599/foo(.*?)bar/
1600    The food is under the bar in the barn.
1601
1602/(.*)(\d*)/
1603    I have 2 numbers: 53147
1604
1605/(.*)(\d+)/
1606    I have 2 numbers: 53147
1607
1608/(.*?)(\d*)/
1609    I have 2 numbers: 53147
1610
1611/(.*?)(\d+)/
1612    I have 2 numbers: 53147
1613
1614/(.*)(\d+)$/
1615    I have 2 numbers: 53147
1616
1617/(.*?)(\d+)$/
1618    I have 2 numbers: 53147
1619
1620/(.*)\b(\d+)$/
1621    I have 2 numbers: 53147
1622
1623/(.*\D)(\d+)$/
1624    I have 2 numbers: 53147
1625
1626/^\D*(?!123)/
1627    ABC123
1628
1629/^(\D*)(?=\d)(?!123)/
1630    ABC445
1631\= Expect no match
1632    ABC123
1633
1634/^[W-]46]/
1635    W46]789
1636    -46]789
1637\= Expect no match
1638    Wall
1639    Zebra
1640    42
1641    [abcd]
1642    ]abcd[
1643
1644/^[W-\]46]/
1645    W46]789
1646    Wall
1647    Zebra
1648    Xylophone
1649    42
1650    [abcd]
1651    ]abcd[
1652    \\backslash
1653\= Expect no match
1654    -46]789
1655    well
1656
1657/\d\d\/\d\d\/\d\d\d\d/
1658    01/01/2000
1659
1660/word (?:[a-zA-Z0-9]+ ){0,10}otherword/
1661    word cat dog elephant mussel cow horse canary baboon snake shark otherword
1662\= Expect no match
1663    word cat dog elephant mussel cow horse canary baboon snake shark
1664
1665/word (?:[a-zA-Z0-9]+ ){0,300}otherword/
1666\= Expect no match
1667    word cat dog elephant mussel cow horse canary baboon snake shark the quick brown fox and the lazy dog and several other words getting close to thirty by now I hope
1668
1669/^(a){0,0}/
1670    bcd
1671    abc
1672    aab
1673
1674/^(a){0,1}/
1675    bcd
1676    abc
1677    aab
1678
1679/^(a){0,2}/
1680    bcd
1681    abc
1682    aab
1683
1684/^(a){0,3}/
1685    bcd
1686    abc
1687    aab
1688    aaa
1689
1690/^(a){0,}/
1691    bcd
1692    abc
1693    aab
1694    aaa
1695    aaaaaaaa
1696
1697/^(a){1,1}/
1698    abc
1699    aab
1700\= Expect no match
1701    bcd
1702
1703/^(a){1,2}/
1704    abc
1705    aab
1706\= Expect no match
1707    bcd
1708
1709/^(a){1,3}/
1710    abc
1711    aab
1712    aaa
1713\= Expect no match
1714    bcd
1715
1716/^(a){1,}/
1717    abc
1718    aab
1719    aaa
1720    aaaaaaaa
1721\= Expect no match
1722    bcd
1723
1724/.*\.gif/
1725    borfle\nbib.gif\nno
1726
1727/.{0,}\.gif/
1728    borfle\nbib.gif\nno
1729
1730/.*\.gif/m
1731    borfle\nbib.gif\nno
1732
1733/.*\.gif/s
1734    borfle\nbib.gif\nno
1735
1736/.*\.gif/ms
1737    borfle\nbib.gif\nno
1738
1739/.*$/
1740    borfle\nbib.gif\nno
1741
1742/.*$/m
1743    borfle\nbib.gif\nno
1744
1745/.*$/s
1746    borfle\nbib.gif\nno
1747
1748/.*$/ms
1749    borfle\nbib.gif\nno
1750
1751/.*$/
1752    borfle\nbib.gif\nno\n
1753
1754/.*$/m
1755    borfle\nbib.gif\nno\n
1756
1757/.*$/s
1758    borfle\nbib.gif\nno\n
1759
1760/.*$/ms
1761    borfle\nbib.gif\nno\n
1762
1763/(.*X|^B)/
1764    abcde\n1234Xyz
1765    BarFoo
1766\= Expect no match
1767    abcde\nBar
1768
1769/(.*X|^B)/m
1770    abcde\n1234Xyz
1771    BarFoo
1772    abcde\nBar
1773
1774/(.*X|^B)/s
1775    abcde\n1234Xyz
1776    BarFoo
1777\= Expect no match
1778    abcde\nBar
1779
1780/(.*X|^B)/ms
1781    abcde\n1234Xyz
1782    BarFoo
1783    abcde\nBar
1784
1785/(?s)(.*X|^B)/
1786    abcde\n1234Xyz
1787    BarFoo
1788\= Expect no match
1789    abcde\nBar
1790
1791/(?s:.*X|^B)/
1792    abcde\n1234Xyz
1793    BarFoo
1794\= Expect no match
1795    abcde\nBar
1796
1797/^.*B/
1798\= Expect no match
1799    abc\nB
1800
1801/(?s)^.*B/
1802    abc\nB
1803
1804/(?m)^.*B/
1805    abc\nB
1806
1807/(?ms)^.*B/
1808    abc\nB
1809
1810/(?ms)^B/
1811    abc\nB
1812
1813/(?s)B$/
1814    B\n
1815
1816/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/
1817    123456654321
1818
1819/^\d\d\d\d\d\d\d\d\d\d\d\d/
1820    123456654321
1821
1822/^[\d][\d][\d][\d][\d][\d][\d][\d][\d][\d][\d][\d]/
1823    123456654321
1824
1825/^[abc]{12}/
1826    abcabcabcabc
1827
1828/^[a-c]{12}/
1829    abcabcabcabc
1830
1831/^(a|b|c){12}/
1832    abcabcabcabc
1833
1834/^[abcdefghijklmnopqrstuvwxy0123456789]/
1835    n
1836\= Expect no match
1837    z
1838
1839/abcde{0,0}/
1840    abcd
1841\= Expect no match
1842    abce
1843
1844/ab[cd]{0,0}e/
1845    abe
1846\= Expect no match
1847    abcde
1848
1849/ab(c){0,0}d/
1850    abd
1851\= Expect no match
1852    abcd
1853
1854/a(b*)/
1855    a
1856    ab
1857    abbbb
1858\= Expect no match
1859    bbbbb
1860
1861/ab\d{0}e/
1862    abe
1863\= Expect no match
1864    ab1e
1865
1866/"([^\\"]+|\\.)*"/
1867    the \"quick\" brown fox
1868    \"the \\\"quick\\\" brown fox\"
1869
1870/.*?/g,aftertext
1871    abc
1872
1873/\b/g,aftertext
1874    abc
1875
1876/\b/g,aftertext
1877    abc
1878
1879//g
1880    abc
1881
1882/<tr([\w\W\s\d][^<>]{0,})><TD([\w\W\s\d][^<>]{0,})>([\d]{0,}\.)(.*)((<BR>([\w\W\s\d][^<>]{0,})|[\s]{0,}))<\/a><\/TD><TD([\w\W\s\d][^<>]{0,})>([\w\W\s\d][^<>]{0,})<\/TD><TD([\w\W\s\d][^<>]{0,})>([\w\W\s\d][^<>]{0,})<\/TD><\/TR>/is
1883  <TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>
1884
1885/a[^a]b/
1886    acb
1887    a\nb
1888
1889/a.b/
1890    acb
1891\= Expect no match
1892    a\nb
1893
1894/a[^a]b/s
1895    acb
1896    a\nb
1897
1898/a.b/s
1899    acb
1900    a\nb
1901
1902/^(b+?|a){1,2}?c/
1903    bac
1904    bbac
1905    bbbac
1906    bbbbac
1907    bbbbbac
1908
1909/^(b+|a){1,2}?c/
1910    bac
1911    bbac
1912    bbbac
1913    bbbbac
1914    bbbbbac
1915
1916/(?!\A)x/m
1917    a\bx\n
1918    a\nx\n
1919\= Expect no match
1920    x\nb\n
1921
1922/(A|B)*?CD/
1923    CD
1924
1925/(A|B)*CD/
1926    CD
1927
1928/(AB)*?\1/
1929    ABABAB
1930
1931/(AB)*\1/
1932    ABABAB
1933
1934/(?<!bar)foo/
1935    foo
1936    catfood
1937    arfootle
1938    rfoosh
1939\= Expect no match
1940    barfoo
1941    towbarfoo
1942
1943/\w{3}(?<!bar)foo/
1944    catfood
1945\= Expect no match
1946    foo
1947    barfoo
1948    towbarfoo
1949
1950/(?<=(foo)a)bar/
1951    fooabar
1952\= Expect no match
1953    bar
1954    foobbar
1955
1956/\Aabc\z/m
1957    abc
1958\= Expect no match
1959    abc\n
1960    qqq\nabc
1961    abc\nzzz
1962    qqq\nabc\nzzz
1963
1964/(?>.*\/)foo/
1965    /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
1966\= Expect no match
1967    /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
1968
1969/(?>(\.\d\d[1-9]?))\d+/
1970    1.230003938
1971    1.875000282
1972\= Expect no match
1973    1.235
1974
1975/^((?>\w+)|(?>\s+))*$/
1976    now is the time for all good men to come to the aid of the party
1977\= Expect no match
1978    this is not a line with only words and spaces!
1979
1980/(\d+)(\w)/
1981    12345a
1982    12345+
1983
1984/((?>\d+))(\w)/
1985    12345a
1986\= Expect no match
1987    12345+
1988
1989/(?>a+)b/
1990    aaab
1991
1992/((?>a+)b)/
1993    aaab
1994
1995/(?>(a+))b/
1996    aaab
1997
1998/(?>b)+/
1999    aaabbbccc
2000
2001/(?>a+|b+|c+)*c/
2002    aaabbbbccccd
2003
2004/((?>[^()]+)|\([^()]*\))+/
2005    ((abc(ade)ufh()()x
2006
2007/\(((?>[^()]+)|\([^()]+\))+\)/
2008    (abc)
2009    (abc(def)xyz)
2010\= Expect no match
2011    ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2012
2013/a(?-i)b/i
2014    ab
2015    Ab
2016\= Expect no match
2017    aB
2018    AB
2019
2020/(a (?x)b c)d e/
2021    a bcd e
2022\= Expect no match
2023    a b cd e
2024    abcd e
2025    a bcde
2026
2027/(a b(?x)c d (?-x)e f)/
2028    a bcde f
2029\= Expect no match
2030    abcdef
2031
2032/(a(?i)b)c/
2033    abc
2034    aBc
2035\= Expect no match
2036    abC
2037    aBC
2038    Abc
2039    ABc
2040    ABC
2041    AbC
2042
2043/a(?i:b)c/
2044    abc
2045    aBc
2046\= Expect no match
2047    ABC
2048    abC
2049    aBC
2050
2051/a(?i:b)*c/
2052    aBc
2053    aBBc
2054\= Expect no match
2055    aBC
2056    aBBC
2057
2058/a(?=b(?i)c)\w\wd/
2059    abcd
2060    abCd
2061\= Expect no match
2062    aBCd
2063    abcD
2064
2065/(?s-i:more.*than).*million/i
2066    more than million
2067    more than MILLION
2068    more \n than Million
2069\= Expect no match
2070    MORE THAN MILLION
2071    more \n than \n million
2072
2073/(?:(?s-i)more.*than).*million/i
2074    more than million
2075    more than MILLION
2076    more \n than Million
2077\= Expect no match
2078    MORE THAN MILLION
2079    more \n than \n million
2080
2081/(?>a(?i)b+)+c/
2082    abc
2083    aBbc
2084    aBBc
2085\= Expect no match
2086    Abc
2087    abAb
2088    abbC
2089
2090/(?=a(?i)b)\w\wc/
2091    abc
2092    aBc
2093\= Expect no match
2094    Ab
2095    abC
2096    aBC
2097
2098/(?<=a(?i)b)(\w\w)c/
2099    abxxc
2100    aBxxc
2101\= Expect no match
2102    Abxxc
2103    ABxxc
2104    abxxC
2105
2106/(?:(a)|b)(?(1)A|B)/
2107    aA
2108    bB
2109\= Expect no match
2110    aB
2111    bA
2112
2113/^(a)?(?(1)a|b)+$/
2114    aa
2115    b
2116    bb
2117\= Expect no match
2118    ab
2119
2120# Perl gets this next one wrong if the pattern ends with $; in that case it
2121# fails to match "12".
2122
2123/^(?(?=abc)\w{3}:|\d\d)/
2124    abc:
2125    12
2126    123
2127\= Expect no match
2128    xyz
2129
2130/^(?(?!abc)\d\d|\w{3}:)$/
2131    abc:
2132    12
2133\= Expect no match
2134    123
2135    xyz
2136
2137/(?(?<=foo)bar|cat)/
2138    foobar
2139    cat
2140    fcat
2141    focat
2142\= Expect no match
2143    foocat
2144
2145/(?(?<!foo)cat|bar)/
2146    foobar
2147    cat
2148    fcat
2149    focat
2150\= Expect no match
2151    foocat
2152
2153/( \( )? [^()]+ (?(1) \) |) /x
2154    abcd
2155    (abcd)
2156    the quick (abcd) fox
2157    (abcd
2158
2159/( \( )? [^()]+ (?(1) \) ) /x
2160    abcd
2161    (abcd)
2162    the quick (abcd) fox
2163    (abcd
2164
2165/^(?(2)a|(1)(2))+$/
2166    12
2167    12a
2168    12aa
2169\= Expect no match
2170    1234
2171
2172/((?i)blah)\s+\1/
2173    blah blah
2174    BLAH BLAH
2175    Blah Blah
2176    blaH blaH
2177\= Expect no match
2178    blah BLAH
2179    Blah blah
2180    blaH blah
2181
2182/((?i)blah)\s+(?i:\1)/
2183    blah blah
2184    BLAH BLAH
2185    Blah Blah
2186    blaH blaH
2187    blah BLAH
2188    Blah blah
2189    blaH blah
2190
2191/((?i)blah)\s+(?m)A(?i:\1)/
2192    blah ABLAH
2193\= Expect no match
2194    blah aBLAH
2195
2196/(?>a*)*/
2197    a
2198    aa
2199    aaaa
2200
2201/(abc|)+/
2202    abc
2203    abcabc
2204    abcabcabc
2205    xyz
2206
2207/([a]*)*/
2208    a
2209    aaaaa
2210
2211/([ab]*)*/
2212    a
2213    b
2214    ababab
2215    aaaabcde
2216    bbbb
2217
2218/([^a]*)*/
2219    b
2220    bbbb
2221    aaa
2222
2223/([^ab]*)*/
2224    cccc
2225    abab
2226
2227/([a]*?)*/
2228    a
2229    aaaa
2230
2231/([ab]*?)*/
2232    a
2233    b
2234    abab
2235    baba
2236
2237/([^a]*?)*/
2238    b
2239    bbbb
2240    aaa
2241
2242/([^ab]*?)*/
2243    c
2244    cccc
2245    baba
2246
2247/(?>a*)*/
2248    a
2249    aaabcde
2250
2251/((?>a*))*/
2252    aaaaa
2253    aabbaa
2254
2255/((?>a*?))*/
2256    aaaaa
2257    aabbaa
2258
2259/(?(?=[^a-z]+[a-z])  \d{2}-[a-z]{3}-\d{2}  |  \d{2}-\d{2}-\d{2} ) /x
2260    12-sep-98
2261    12-09-98
2262\= Expect no match
2263    sep-12-98
2264
2265/(?<=(foo))bar\1/
2266    foobarfoo
2267    foobarfootling
2268\= Expect no match
2269    foobar
2270    barfoo
2271
2272/(?i:saturday|sunday)/
2273    saturday
2274    sunday
2275    Saturday
2276    Sunday
2277    SATURDAY
2278    SUNDAY
2279    SunDay
2280
2281/(a(?i)bc|BB)x/
2282    abcx
2283    aBCx
2284    bbx
2285    BBx
2286\= Expect no match
2287    abcX
2288    aBCX
2289    bbX
2290    BBX
2291
2292/^([ab](?i)[cd]|[ef])/
2293    ac
2294    aC
2295    bD
2296    elephant
2297    Europe
2298    frog
2299    France
2300\= Expect no match
2301    Africa
2302
2303/^(ab|a(?i)[b-c](?m-i)d|x(?i)y|z)/
2304    ab
2305    aBd
2306    xy
2307    xY
2308    zebra
2309    Zambesi
2310\= Expect no match
2311    aCD
2312    XY
2313
2314/(?<=foo\n)^bar/m
2315    foo\nbar
2316\= Expect no match
2317    bar
2318    baz\nbar
2319
2320/(?<=(?<!foo)bar)baz/
2321    barbaz
2322    barbarbaz
2323    koobarbaz
2324\= Expect no match
2325    baz
2326    foobarbaz
2327
2328# The cases of aaaa and aaaaaa are missed out below because Perl does things
2329# differently. We know that odd, and maybe incorrect, things happen with
2330# recursive references in Perl, as far as 5.11.3 - see some stuff in test #2.
2331
2332/^(a\1?){4}$/
2333    aaaaa
2334    aaaaaaa
2335    aaaaaaaaaa
2336\= Expect no match
2337    a
2338    aa
2339    aaa
2340    aaaaaaaa
2341    aaaaaaaaa
2342    aaaaaaaaaaa
2343    aaaaaaaaaaaa
2344    aaaaaaaaaaaaa
2345    aaaaaaaaaaaaaa
2346    aaaaaaaaaaaaaaa
2347    aaaaaaaaaaaaaaaa
2348
2349/^(a\1?)(a\1?)(a\2?)(a\3?)$/
2350    aaaa
2351    aaaaa
2352    aaaaaa
2353    aaaaaaa
2354    aaaaaaaaaa
2355\= Expect no match
2356    a
2357    aa
2358    aaa
2359    aaaaaaaa
2360    aaaaaaaaa
2361    aaaaaaaaaaa
2362    aaaaaaaaaaaa
2363    aaaaaaaaaaaaa
2364    aaaaaaaaaaaaaa
2365    aaaaaaaaaaaaaaa
2366    aaaaaaaaaaaaaaaa
2367
2368# The following tests are taken from the Perl 5.005 test suite; some of them
2369# are compatible with 5.004, but I'd rather not have to sort them out.
2370
2371/abc/
2372    abc
2373    xabcy
2374    ababc
2375\= Expect no match
2376    xbc
2377    axc
2378    abx
2379
2380/ab*c/
2381    abc
2382
2383/ab*bc/
2384    abc
2385    abbc
2386    abbbbc
2387
2388/.{1}/
2389    abbbbc
2390
2391/.{3,4}/
2392    abbbbc
2393
2394/ab{0,}bc/
2395    abbbbc
2396
2397/ab+bc/
2398    abbc
2399\= Expect no match
2400    abc
2401    abq
2402
2403/ab{1,}bc/
2404
2405/ab+bc/
2406    abbbbc
2407
2408/ab{1,}bc/
2409    abbbbc
2410
2411/ab{1,3}bc/
2412    abbbbc
2413
2414/ab{3,4}bc/
2415    abbbbc
2416
2417/ab{4,5}bc/
2418\= Expect no match
2419    abq
2420    abbbbc
2421
2422/ab?bc/
2423    abbc
2424    abc
2425
2426/ab{0,1}bc/
2427    abc
2428
2429/ab?bc/
2430
2431/ab?c/
2432    abc
2433
2434/ab{0,1}c/
2435    abc
2436
2437/^abc$/
2438    abc
2439\= Expect no match
2440    abbbbc
2441    abcc
2442
2443/^abc/
2444    abcc
2445
2446/^abc$/
2447
2448/abc$/
2449    aabc
2450\= Expect no match
2451    aabcd
2452
2453/^/
2454    abc
2455
2456/$/
2457    abc
2458
2459/a.c/
2460    abc
2461    axc
2462
2463/a.*c/
2464    axyzc
2465
2466/a[bc]d/
2467    abd
2468\= Expect no match
2469    axyzd
2470    abc
2471
2472/a[b-d]e/
2473    ace
2474
2475/a[b-d]/
2476    aac
2477
2478/a[-b]/
2479    a-
2480
2481/a[b-]/
2482    a-
2483
2484/a]/
2485    a]
2486
2487/a[]]b/
2488    a]b
2489
2490/a[^bc]d/
2491    aed
2492\= Expect no match
2493    abd
2494    abd
2495
2496/a[^-b]c/
2497    adc
2498
2499/a[^]b]c/
2500    adc
2501    a-c
2502\= Expect no match
2503    a]c
2504
2505/\ba\b/
2506    a-
2507    -a
2508    -a-
2509
2510/\by\b/
2511\= Expect no match
2512    xy
2513    yz
2514    xyz
2515
2516/\Ba\B/
2517\= Expect no match
2518    a-
2519    -a
2520    -a-
2521
2522/\By\b/
2523    xy
2524
2525/\by\B/
2526    yz
2527
2528/\By\B/
2529    xyz
2530
2531/\w/
2532    a
2533
2534/\W/
2535    -
2536\= Expect no match
2537    a
2538
2539/a\sb/
2540    a b
2541
2542/a\Sb/
2543    a-b
2544\= Expect no match
2545    a b
2546
2547/\d/
2548    1
2549
2550/\D/
2551    -
2552\= Expect no match
2553    1
2554
2555/[\w]/
2556    a
2557
2558/[\W]/
2559    -
2560\= Expect no match
2561    a
2562
2563/a[\s]b/
2564    a b
2565
2566/a[\S]b/
2567    a-b
2568\= Expect no match
2569    a b
2570
2571/[\d]/
2572    1
2573
2574/[\D]/
2575    -
2576\= Expect no match
2577    1
2578
2579/ab|cd/
2580    abc
2581    abcd
2582
2583/()ef/
2584    def
2585
2586/$b/
2587
2588/a\(b/
2589    a(b
2590
2591/a\(*b/
2592    ab
2593    a((b
2594
2595/a\\b/
2596    a\\b
2597
2598/((a))/
2599    abc
2600
2601/(a)b(c)/
2602    abc
2603
2604/a+b+c/
2605    aabbabc
2606
2607/a{1,}b{1,}c/
2608    aabbabc
2609
2610/a.+?c/
2611    abcabc
2612
2613/(a+|b)*/
2614    ab
2615
2616/(a+|b){0,}/
2617    ab
2618
2619/(a+|b)+/
2620    ab
2621
2622/(a+|b){1,}/
2623    ab
2624
2625/(a+|b)?/
2626    ab
2627
2628/(a+|b){0,1}/
2629    ab
2630
2631/[^ab]*/
2632    cde
2633
2634/abc/
2635\= Expect no match
2636    b
2637
2638/a*/
2639    \
2640
2641/([abc])*d/
2642    abbbcd
2643
2644/([abc])*bcd/
2645    abcd
2646
2647/a|b|c|d|e/
2648    e
2649
2650/(a|b|c|d|e)f/
2651    ef
2652
2653/abcd*efg/
2654    abcdefg
2655
2656/ab*/
2657    xabyabbbz
2658    xayabbbz
2659
2660/(ab|cd)e/
2661    abcde
2662
2663/[abhgefdc]ij/
2664    hij
2665
2666/^(ab|cd)e/
2667
2668/(abc|)ef/
2669    abcdef
2670
2671/(a|b)c*d/
2672    abcd
2673
2674/(ab|ab*)bc/
2675    abc
2676
2677/a([bc]*)c*/
2678    abc
2679
2680/a([bc]*)(c*d)/
2681    abcd
2682
2683/a([bc]+)(c*d)/
2684    abcd
2685
2686/a([bc]*)(c+d)/
2687    abcd
2688
2689/a[bcd]*dcdcde/
2690    adcdcde
2691
2692/a[bcd]+dcdcde/
2693\= Expect no match
2694    abcde
2695    adcdcde
2696
2697/(ab|a)b*c/
2698    abc
2699
2700/((a)(b)c)(d)/
2701    abcd
2702
2703/[a-zA-Z_][a-zA-Z0-9_]*/
2704    alpha
2705
2706/^a(bc+|b[eh])g|.h$/
2707    abh
2708
2709/(bc+d$|ef*g.|h?i(j|k))/
2710    effgz
2711    ij
2712    reffgz
2713\= Expect no match
2714    effg
2715    bcdd
2716
2717/((((((((((a))))))))))/
2718    a
2719
2720/((((((((((a))))))))))\10/
2721    aa
2722
2723/(((((((((a)))))))))/
2724    a
2725
2726/multiple words of text/
2727\= Expect no match
2728    aa
2729    uh-uh
2730
2731/multiple words/
2732    multiple words, yeah
2733
2734/(.*)c(.*)/
2735    abcde
2736
2737/\((.*), (.*)\)/
2738    (a, b)
2739
2740/[k]/
2741
2742/abcd/
2743    abcd
2744
2745/a(bc)d/
2746    abcd
2747
2748/a[-]?c/
2749    ac
2750
2751/(abc)\1/
2752    abcabc
2753
2754/([a-c]*)\1/
2755    abcabc
2756
2757/(a)|\1/
2758    a
2759    ab
2760\= Expect no match
2761    x
2762
2763/(([a-c])b*?\2)*/
2764    ababbbcbc
2765
2766/(([a-c])b*?\2){3}/
2767    ababbbcbc
2768
2769/((\3|b)\2(a)x)+/
2770    aaaxabaxbaaxbbax
2771
2772/((\3|b)\2(a)){2,}/
2773    bbaababbabaaaaabbaaaabba
2774
2775/abc/i
2776    ABC
2777    XABCY
2778    ABABC
2779\= Expect no match
2780    aaxabxbaxbbx
2781    XBC
2782    AXC
2783    ABX
2784
2785/ab*c/i
2786    ABC
2787
2788/ab*bc/i
2789    ABC
2790    ABBC
2791
2792/ab*?bc/i
2793    ABBBBC
2794
2795/ab{0,}?bc/i
2796    ABBBBC
2797
2798/ab+?bc/i
2799    ABBC
2800
2801/ab+bc/i
2802\= Expect no match
2803    ABC
2804    ABQ
2805
2806/ab{1,}bc/i
2807
2808/ab+bc/i
2809    ABBBBC
2810
2811/ab{1,}?bc/i
2812    ABBBBC
2813
2814/ab{1,3}?bc/i
2815    ABBBBC
2816
2817/ab{3,4}?bc/i
2818    ABBBBC
2819
2820/ab{4,5}?bc/i
2821\= Expect no match
2822    ABQ
2823    ABBBBC
2824
2825/ab??bc/i
2826    ABBC
2827    ABC
2828
2829/ab{0,1}?bc/i
2830    ABC
2831
2832/ab??bc/i
2833
2834/ab??c/i
2835    ABC
2836
2837/ab{0,1}?c/i
2838    ABC
2839
2840/^abc$/i
2841    ABC
2842\= Expect no match
2843    ABBBBC
2844    ABCC
2845
2846/^abc/i
2847    ABCC
2848
2849/^abc$/i
2850
2851/abc$/i
2852    AABC
2853
2854/^/i
2855    ABC
2856
2857/$/i
2858    ABC
2859
2860/a.c/i
2861    ABC
2862    AXC
2863
2864/a.*?c/i
2865    AXYZC
2866
2867/a.*c/i
2868    AABC
2869\= Expect no match
2870    AXYZD
2871
2872/a[bc]d/i
2873    ABD
2874
2875/a[b-d]e/i
2876    ACE
2877\= Expect no match
2878    ABC
2879    ABD
2880
2881/a[b-d]/i
2882    AAC
2883
2884/a[-b]/i
2885    A-
2886
2887/a[b-]/i
2888    A-
2889
2890/a]/i
2891    A]
2892
2893/a[]]b/i
2894    A]B
2895
2896/a[^bc]d/i
2897    AED
2898
2899/a[^-b]c/i
2900    ADC
2901\= Expect no match
2902    ABD
2903    A-C
2904
2905/a[^]b]c/i
2906    ADC
2907
2908/ab|cd/i
2909    ABC
2910    ABCD
2911
2912/()ef/i
2913    DEF
2914
2915/$b/i
2916\= Expect no match
2917    A]C
2918    B
2919
2920/a\(b/i
2921    A(B
2922
2923/a\(*b/i
2924    AB
2925    A((B
2926
2927/a\\b/i
2928    A\\b
2929    a\\B
2930
2931/((a))/i
2932    ABC
2933
2934/(a)b(c)/i
2935    ABC
2936
2937/a+b+c/i
2938    AABBABC
2939
2940/a{1,}b{1,}c/i
2941    AABBABC
2942
2943/a.+?c/i
2944    ABCABC
2945
2946/a.*?c/i
2947    ABCABC
2948
2949/a.{0,5}?c/i
2950    ABCABC
2951
2952/(a+|b)*/i
2953    AB
2954
2955/(a+|b){0,}/i
2956    AB
2957
2958/(a+|b)+/i
2959    AB
2960
2961/(a+|b){1,}/i
2962    AB
2963
2964/(a+|b)?/i
2965    AB
2966
2967/(a+|b){0,1}/i
2968    AB
2969
2970/(a+|b){0,1}?/i
2971    AB
2972
2973/[^ab]*/i
2974    CDE
2975
2976/([abc])*d/i
2977    ABBBCD
2978
2979/([abc])*bcd/i
2980    ABCD
2981
2982/a|b|c|d|e/i
2983    E
2984
2985/(a|b|c|d|e)f/i
2986    EF
2987
2988/abcd*efg/i
2989    ABCDEFG
2990
2991/ab*/i
2992    XABYABBBZ
2993    XAYABBBZ
2994
2995/(ab|cd)e/i
2996    ABCDE
2997
2998/[abhgefdc]ij/i
2999    HIJ
3000
3001/^(ab|cd)e/i
3002\= Expect no match
3003    ABCDE
3004
3005/(abc|)ef/i
3006    ABCDEF
3007
3008/(a|b)c*d/i
3009    ABCD
3010
3011/(ab|ab*)bc/i
3012    ABC
3013
3014/a([bc]*)c*/i
3015    ABC
3016
3017/a([bc]*)(c*d)/i
3018    ABCD
3019
3020/a([bc]+)(c*d)/i
3021    ABCD
3022
3023/a([bc]*)(c+d)/i
3024    ABCD
3025
3026/a[bcd]*dcdcde/i
3027    ADCDCDE
3028
3029/a[bcd]+dcdcde/i
3030
3031/(ab|a)b*c/i
3032    ABC
3033
3034/((a)(b)c)(d)/i
3035    ABCD
3036
3037/[a-zA-Z_][a-zA-Z0-9_]*/i
3038    ALPHA
3039
3040/^a(bc+|b[eh])g|.h$/i
3041    ABH
3042
3043/(bc+d$|ef*g.|h?i(j|k))/i
3044    EFFGZ
3045    IJ
3046    REFFGZ
3047\= Expect no match
3048    ADCDCDE
3049    EFFG
3050    BCDD
3051
3052/((((((((((a))))))))))/i
3053    A
3054
3055/((((((((((a))))))))))\10/i
3056    AA
3057
3058/(((((((((a)))))))))/i
3059    A
3060
3061/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))/i
3062    A
3063
3064/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))/i
3065    C
3066
3067/multiple words of text/i
3068\= Expect no match
3069    AA
3070    UH-UH
3071
3072/multiple words/i
3073    MULTIPLE WORDS, YEAH
3074
3075/(.*)c(.*)/i
3076    ABCDE
3077
3078/\((.*), (.*)\)/i
3079    (A, B)
3080
3081/[k]/i
3082
3083/abcd/i
3084    ABCD
3085
3086/a(bc)d/i
3087    ABCD
3088
3089/a[-]?c/i
3090    AC
3091
3092/(abc)\1/i
3093    ABCABC
3094
3095/([a-c]*)\1/i
3096    ABCABC
3097
3098/a(?!b)./
3099    abad
3100
3101/a(?=d)./
3102    abad
3103
3104/a(?=c|d)./
3105    abad
3106
3107/a(?:b|c|d)(.)/
3108    ace
3109
3110/a(?:b|c|d)*(.)/
3111    ace
3112
3113/a(?:b|c|d)+?(.)/
3114    ace
3115    acdbcdbe
3116
3117/a(?:b|c|d)+(.)/
3118    acdbcdbe
3119
3120/a(?:b|c|d){2}(.)/
3121    acdbcdbe
3122
3123/a(?:b|c|d){4,5}(.)/
3124    acdbcdbe
3125
3126/a(?:b|c|d){4,5}?(.)/
3127    acdbcdbe
3128
3129/a(?:b|c|d){6,7}(.)/
3130    acdbcdbe
3131
3132/a(?:b|c|d){6,7}?(.)/
3133    acdbcdbe
3134
3135/a(?:b|c|d){5,6}(.)/
3136    acdbcdbe
3137
3138/a(?:b|c|d){5,6}?(.)/
3139    acdbcdbe
3140
3141/a(?:b|c|d){5,7}(.)/
3142    acdbcdbe
3143
3144/a(?:b|c|d){5,7}?(.)/
3145    acdbcdbe
3146
3147/a(?:b|(c|e){1,2}?|d)+?(.)/
3148    ace
3149
3150/^(.+)?B/
3151    AB
3152
3153/^([^a-z])|(\^)$/
3154    .
3155
3156/^[<>]&/
3157    <&OUT
3158
3159/^(a\1?){4}$/
3160    aaaaaaaaaa
3161\= Expect no match
3162    AB
3163    aaaaaaaaa
3164    aaaaaaaaaaa
3165
3166/^(a(?(1)\1)){4}$/
3167    aaaaaaaaaa
3168\= Expect no match
3169    aaaaaaaaa
3170    aaaaaaaaaaa
3171
3172/(?<=a)b/
3173    ab
3174\= Expect no match
3175    cb
3176    b
3177
3178/(?<!c)b/
3179    ab
3180    b
3181    b
3182
3183/(?:..)*a/
3184    aba
3185
3186/(?:..)*?a/
3187    aba
3188
3189/^(?:b|a(?=(.)))*\1/
3190    abc
3191
3192/^(){3,5}/
3193    abc
3194
3195/^(a+)*ax/
3196    aax
3197
3198/^((a|b)+)*ax/
3199    aax
3200
3201/^((a|bc)+)*ax/
3202    aax
3203
3204/(a|x)*ab/
3205    cab
3206
3207/(a)*ab/
3208    cab
3209
3210/(?:(?i)a)b/
3211    ab
3212
3213/((?i)a)b/
3214    ab
3215
3216/(?:(?i)a)b/
3217    Ab
3218
3219/((?i)a)b/
3220    Ab
3221
3222/(?:(?i)a)b/
3223\= Expect no match
3224    cb
3225    aB
3226
3227/((?i)a)b/
3228
3229/(?i:a)b/
3230    ab
3231
3232/((?i:a))b/
3233    ab
3234
3235/(?i:a)b/
3236    Ab
3237
3238/((?i:a))b/
3239    Ab
3240
3241/(?i:a)b/
3242\= Expect no match
3243    aB
3244    aB
3245
3246/((?i:a))b/
3247
3248/(?:(?-i)a)b/i
3249    ab
3250
3251/((?-i)a)b/i
3252    ab
3253
3254/(?:(?-i)a)b/i
3255    aB
3256
3257/((?-i)a)b/i
3258    aB
3259
3260/(?:(?-i)a)b/i
3261    aB
3262\= Expect no match
3263    Ab
3264    AB
3265
3266/(?-i:a)b/i
3267    ab
3268
3269/((?-i:a))b/i
3270    ab
3271
3272/(?-i:a)b/i
3273    aB
3274
3275/((?-i:a))b/i
3276    aB
3277
3278/(?-i:a)b/i
3279\= Expect no match
3280    AB
3281    Ab
3282
3283/((?-i:a))b/i
3284
3285/(?-i:a)b/i
3286    aB
3287
3288/((?-i:a))b/i
3289    aB
3290
3291/(?-i:a)b/i
3292\= Expect no match
3293    Ab
3294    AB
3295
3296/((?-i:a))b/i
3297
3298/((?-i:a.))b/i
3299\= Expect no match
3300    AB
3301    a\nB
3302
3303/((?s-i:a.))b/i
3304    a\nB
3305
3306/(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))/
3307    cabbbb
3308
3309/(?:c|d)(?:)(?:aaaaaaaa(?:)(?:bbbbbbbb)(?:bbbbbbbb(?:))(?:bbbbbbbb(?:)(?:bbbbbbbb)))/
3310    caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
3311
3312/(ab)\d\1/i
3313    Ab4ab
3314    ab4Ab
3315
3316/foo\w*\d{4}baz/
3317    foobar1234baz
3318
3319/x(~~)*(?:(?:F)?)?/
3320    x~~
3321
3322/^a(?#xxx){3}c/
3323    aaac
3324
3325/^a (?#xxx) (?#yyy) {3}c/x
3326    aaac
3327
3328/(?<![cd])b/
3329\= Expect no match
3330    B\nB
3331    dbcb
3332
3333/(?<![cd])[ab]/
3334    dbaacb
3335
3336/(?<!(c|d))b/
3337
3338/(?<!(c|d))[ab]/
3339    dbaacb
3340
3341/(?<!cd)[ab]/
3342    cdaccb
3343
3344/^(?:a?b?)*$/
3345    \
3346    a
3347    ab
3348    aaa
3349\= Expect no match
3350    dbcb
3351    a--
3352    aa--
3353
3354/((?s)^a(.))((?m)^b$)/
3355    a\nb\nc\n
3356
3357/((?m)^b$)/
3358    a\nb\nc\n
3359
3360/(?m)^b/
3361    a\nb\n
3362
3363/(?m)^(b)/
3364    a\nb\n
3365
3366/((?m)^b)/
3367    a\nb\n
3368
3369/\n((?m)^b)/
3370    a\nb\n
3371
3372/((?s).)c(?!.)/
3373    a\nb\nc\n
3374    a\nb\nc\n
3375
3376/((?s)b.)c(?!.)/
3377    a\nb\nc\n
3378    a\nb\nc\n
3379
3380/^b/
3381
3382/()^b/
3383\= Expect no match
3384    a\nb\nc\n
3385    a\nb\nc\n
3386
3387/((?m)^b)/
3388    a\nb\nc\n
3389
3390/(x)?(?(1)a|b)/
3391\= Expect no match
3392    a
3393    a
3394
3395/(x)?(?(1)b|a)/
3396    a
3397
3398/()?(?(1)b|a)/
3399    a
3400
3401/()(?(1)b|a)/
3402
3403/()?(?(1)a|b)/
3404    a
3405
3406/^(\()?blah(?(1)(\)))$/
3407    (blah)
3408    blah
3409\= Expect no match
3410    a
3411    blah)
3412    (blah
3413
3414/^(\(+)?blah(?(1)(\)))$/
3415    (blah)
3416    blah
3417\= Expect no match
3418    blah)
3419    (blah
3420
3421/(?(?!a)a|b)/
3422
3423/(?(?!a)b|a)/
3424    a
3425
3426/(?(?=a)b|a)/
3427\= Expect no match
3428    a
3429    a
3430
3431/(?(?=a)a|b)/
3432    a
3433
3434/(?=(a+?))(\1ab)/
3435    aaab
3436
3437/^(?=(a+?))\1ab/
3438
3439/(\w+:)+/
3440    one:
3441
3442/$(?<=^(a))/
3443    a
3444
3445/(?=(a+?))(\1ab)/
3446    aaab
3447
3448/^(?=(a+?))\1ab/
3449\= Expect no match
3450    aaab
3451    aaab
3452
3453/([\w:]+::)?(\w+)$/
3454    abcd
3455    xy:z:::abcd
3456
3457/^[^bcd]*(c+)/
3458    aexycd
3459
3460/(a*)b+/
3461    caab
3462
3463/([\w:]+::)?(\w+)$/
3464    abcd
3465    xy:z:::abcd
3466\= Expect no match
3467    abcd:
3468    abcd:
3469
3470/^[^bcd]*(c+)/
3471    aexycd
3472
3473/(>a+)ab/
3474
3475/(?>a+)b/
3476    aaab
3477
3478/([[:]+)/
3479    a:[b]:
3480
3481/([[=]+)/
3482    a=[b]=
3483
3484/([[.]+)/
3485    a.[b].
3486
3487/((?>a+)b)/
3488    aaab
3489
3490/(?>(a+))b/
3491    aaab
3492
3493/((?>[^()]+)|\([^()]*\))+/
3494    ((abc(ade)ufh()()x
3495
3496/a\Z/
3497\= Expect no match
3498    aaab
3499    a\nb\n
3500
3501/b\Z/
3502    a\nb\n
3503
3504/b\z/
3505
3506/b\Z/
3507    a\nb
3508
3509/b\z/
3510    a\nb
3511
3512/^(?>(?(1)\.|())[^\W_](?>[a-z0-9-]*[^\W_])?)+$/
3513    a
3514    abc
3515    a-b
3516    0-9
3517    a.b
3518    5.6.7
3519    the.quick.brown.fox
3520    a100.b200.300c
3521    12-ab.1245
3522\= Expect no match
3523    \
3524    .a
3525    -a
3526    a-
3527    a.
3528    a_b
3529    a.-
3530    a..
3531    ab..bc
3532    the.quick.brown.fox-
3533    the.quick.brown.fox.
3534    the.quick.brown.fox_
3535    the.quick.brown.fox+
3536
3537/(?>.*)(?<=(abcd|wxyz))/
3538    alphabetabcd
3539    endingwxyz
3540\= Expect no match
3541    a rather long string that doesn't end with one of them
3542
3543/word (?>(?:(?!otherword)[a-zA-Z0-9]+ ){0,30})otherword/
3544    word cat dog elephant mussel cow horse canary baboon snake shark otherword
3545\= Expect no match
3546    word cat dog elephant mussel cow horse canary baboon snake shark
3547
3548/word (?>[a-zA-Z0-9]+ ){0,30}otherword/
3549\= Expect no match
3550    word cat dog elephant mussel cow horse canary baboon snake shark the quick brown fox and the lazy dog and several other words getting close to thirty by now I hope
3551
3552/(?<=\d{3}(?!999))foo/
3553    999foo
3554    123999foo
3555\= Expect no match
3556    123abcfoo
3557
3558/(?<=(?!...999)\d{3})foo/
3559    999foo
3560    123999foo
3561\= Expect no match
3562    123abcfoo
3563
3564/(?<=\d{3}(?!999)...)foo/
3565    123abcfoo
3566    123456foo
3567\= Expect no match
3568    123999foo
3569
3570/(?<=\d{3}...)(?<!999)foo/
3571    123abcfoo
3572    123456foo
3573\= Expect no match
3574    123999foo
3575
3576/<a[\s]+href[\s]*=[\s]*          # find <a href=
3577 ([\"\'])?                       # find single or double quote
3578 (?(1) (.*?)\1 | ([^\s]+))       # if quote found, match up to next matching
3579                                 # quote, otherwise match up to next space
3580/isx
3581    <a href=abcd xyz
3582    <a href=\"abcd xyz pqr\" cats
3583    <a href=\'abcd xyz pqr\' cats
3584
3585/<a\s+href\s*=\s*                # find <a href=
3586 (["'])?                         # find single or double quote
3587 (?(1) (.*?)\1 | (\S+))          # if quote found, match up to next matching
3588                                 # quote, otherwise match up to next space
3589/isx
3590    <a href=abcd xyz
3591    <a href=\"abcd xyz pqr\" cats
3592    <a href       =       \'abcd xyz pqr\' cats
3593
3594/<a\s+href(?>\s*)=(?>\s*)        # find <a href=
3595 (["'])?                         # find single or double quote
3596 (?(1) (.*?)\1 | (\S+))          # if quote found, match up to next matching
3597                                 # quote, otherwise match up to next space
3598/isx
3599    <a href=abcd xyz
3600    <a href=\"abcd xyz pqr\" cats
3601    <a href       =       \'abcd xyz pqr\' cats
3602
3603/(Z()|A)*/
3604    ZABCDEFG
3605
3606/(Z(())|A)*/
3607    ZABCDEFG
3608
3609/((?>Z)+|A)*/
3610    ZABCDEFG
3611
3612/((?>)+|A)*/
3613    ZABCDEFG
3614
3615/a*/g
3616    abbab
3617
3618/[[:space:]]+/
3619    > \x09\x0a\x0c\x0d\x0b<
3620
3621/[[:blank:]]+/
3622    > \x09\x0a\x0c\x0d\x0b<
3623
3624/[\s]+/
3625    > \x09\x0a\x0c\x0d\x0b<
3626
3627/\s+/
3628    > \x09\x0a\x0c\x0d\x0b<
3629
3630/ab/x
3631    ab
3632
3633/(?!\A)x/m
3634    a\nxb\n
3635
3636/(?!^)x/m
3637\= Expect no match
3638    a\nxb\n
3639
3640/abc\Qabc\Eabc/
3641    abcabcabc
3642
3643/abc\Q(*+|\Eabc/
3644    abc(*+|abc
3645
3646/   abc\Q abc\Eabc/x
3647    abc abcabc
3648\= Expect no match
3649    abcabcabc
3650
3651/abc#comment
3652    \Q#not comment
3653    literal\E/x
3654    abc#not comment\n    literal
3655
3656/abc#comment
3657    \Q#not comment
3658    literal/x
3659    abc#not comment\n    literal
3660
3661/abc#comment
3662    \Q#not comment
3663    literal\E #more comment
3664    /x
3665    abc#not comment\n    literal
3666
3667/abc#comment
3668    \Q#not comment
3669    literal\E #more comment/x
3670    abc#not comment\n    literal
3671
3672/\Qabc\$xyz\E/
3673    abc\\\$xyz
3674
3675/\Qabc\E\$\Qxyz\E/
3676    abc\$xyz
3677
3678/\Gabc/
3679    abc
3680\= Expect no match
3681    xyzabc
3682
3683/\Gabc./g
3684    abc1abc2xyzabc3
3685
3686/abc./g
3687    abc1abc2xyzabc3
3688
3689/a(?x: b c )d/
3690    XabcdY
3691\= Expect no match
3692    Xa b c d Y
3693
3694/((?x)x y z | a b c)/
3695    XabcY
3696    AxyzB
3697
3698/(?i)AB(?-i)C/
3699    XabCY
3700\= Expect no match
3701    XabcY
3702
3703/((?i)AB(?-i)C|D)E/
3704    abCE
3705    DE
3706\= Expect no match
3707    abcE
3708    abCe
3709    dE
3710    De
3711
3712/(.*)\d+\1/
3713    abc123abc
3714    abc123bc
3715
3716/(.*)\d+\1/s
3717    abc123abc
3718    abc123bc
3719
3720/((.*))\d+\1/
3721    abc123abc
3722    abc123bc
3723
3724# This tests for an IPv6 address in the form where it can have up to
3725# eight components, one and only one of which is empty. This must be
3726# an internal component.
3727
3728/^(?!:)                       # colon disallowed at start
3729  (?:                         # start of item
3730    (?: [0-9a-f]{1,4} |       # 1-4 hex digits or
3731    (?(1)0 | () ) )           # if null previously matched, fail; else null
3732    :                         # followed by colon
3733  ){1,7}                      # end item; 1-7 of them required
3734  [0-9a-f]{1,4} $             # final hex number at end of string
3735  (?(1)|.)                    # check that there was an empty component
3736  /ix
3737    a123::a123
3738    a123:b342::abcd
3739    a123:b342::324e:abcd
3740    a123:ddde:b342::324e:abcd
3741    a123:ddde:b342::324e:dcba:abcd
3742    a123:ddde:9999:b342::324e:dcba:abcd
3743\= Expect no match
3744    1:2:3:4:5:6:7:8
3745    a123:bce:ddde:9999:b342::324e:dcba:abcd
3746    a123::9999:b342::324e:dcba:abcd
3747    abcde:2:3:4:5:6:7:8
3748    ::1
3749    abcd:fee0:123::
3750    :1
3751    1:
3752
3753/[z\Qa-d]\E]/
3754    z
3755    a
3756    -
3757    d
3758    ]
3759\= Expect no match
3760    b
3761
3762/(a+)*b/
3763\= Expect no match
3764    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3765
3766/(?i)reg(?:ul(?:[a�]|ae)r|ex)/
3767    REGular
3768    regulaer
3769    Regex
3770    regul�r
3771
3772/����[�-��-�]+/
3773    �����
3774    �����
3775    �����
3776    �����
3777
3778/(?<=Z)X./
3779  \x84XAZXB
3780
3781/ab cd (?x) de fg/
3782    ab cd defg
3783
3784/ab cd(?x) de fg/
3785    ab cddefg
3786\= Expect no match
3787    abcddefg
3788
3789/(?<![^f]oo)(bar)/
3790    foobarX
3791\= Expect no match
3792    boobarX
3793
3794/(?<![^f])X/
3795    offX
3796\= Expect no match
3797    onyX
3798
3799/(?<=[^f])X/
3800    onyX
3801\= Expect no match
3802    offX
3803
3804/^/gm
3805    a\nb\nc\n
3806    \
3807
3808/(?<=C\n)^/gm
3809    A\nC\nC\n
3810
3811/(?:(?(1)a|b)(X))+/
3812    bXaX
3813
3814/(?:(?(1)\1a|b)(X|Y))+/
3815    bXXaYYaY
3816    bXYaXXaX
3817
3818/()()()()()()()()()(?:(?(10)\10a|b)(X|Y))+/
3819    bXXaYYaY
3820
3821/[[,abc,]+]/
3822    abc]
3823    a,b]
3824    [a,b,c]
3825
3826/(?-x: )/x
3827    A\x20B
3828
3829/(?x)(?-x: \s*#\s*)/
3830    A # B
3831\= Expect no match
3832    #
3833    A s#s B
3834
3835/(?x-is)(?:(?-ixs) \s*#\s*) include/
3836    A #include
3837\= Expect no match
3838    A#include
3839    A #Include
3840
3841/a*b*\w/
3842    aaabbbb
3843    aaaa
3844    a
3845
3846/a*b?\w/
3847    aaabbbb
3848    aaaa
3849    a
3850
3851/a*b{0,4}\w/
3852    aaabbbb
3853    aaaa
3854    a
3855
3856/a*b{0,}\w/
3857    aaabbbb
3858    aaaa
3859    a
3860
3861/a*\d*\w/
3862    0a
3863    a
3864
3865/a*b *\w/x
3866    a
3867
3868/a*b#comment
3869  *\w/x
3870    a
3871
3872/a* b *\w/x
3873    a
3874
3875/^\w+=.*(\\\n.*)*/
3876    abc=xyz\\\npqr
3877
3878/(?=(\w+))\1:/
3879    abcd:
3880
3881/^(?=(\w+))\1:/
3882    abcd:
3883
3884/^\Eabc/
3885    abc
3886
3887/^[\Eabc]/
3888    a
3889\= Expect no match
3890    E
3891
3892/^[a-\Ec]/
3893    b
3894\= Expect no match
3895    -
3896    E
3897
3898/^[a\E\E-\Ec]/
3899    b
3900\= Expect no match
3901    -
3902    E
3903
3904/^[\E\Qa\E-\Qz\E]+/
3905    b
3906\= Expect no match
3907    -
3908
3909/^[a\Q]bc\E]/
3910    a
3911    ]
3912    c
3913
3914/^[a-\Q\E]/
3915    a
3916    -
3917
3918/^(a()*)*/
3919    aaaa
3920
3921/^(?:a(?:(?:))*)*/
3922    aaaa
3923
3924/^(a()+)+/
3925    aaaa
3926
3927/^(?:a(?:(?:))+)+/
3928    aaaa
3929
3930/(a){0,3}(?(1)b|(c|))*D/
3931    abbD
3932    ccccD
3933    D
3934
3935/(a|)*\d/
3936  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
3937\= Expect no match
3938  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3939
3940/(?>a|)*\d/
3941  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
3942\= Expect no match
3943  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3944
3945/(?:a|)*\d/
3946  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
3947\= Expect no match
3948  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3949
3950/\Z/g
3951  abc\n
3952
3953/^(?s)(?>.*)(?<!\n)/
3954  abc
3955\= Expect no match
3956  abc\n
3957
3958/^(?![^\n]*\n\z)/
3959  abc
3960\= Expect no match
3961  abc\n
3962
3963/\z(?<!\n)/
3964  abc
3965\= Expect no match
3966  abc\n
3967
3968/(.*(.)?)*/
3969    abcd
3970
3971/( (A | (?(1)0|) )*   )/x
3972    abcd
3973
3974/( ( (?(1)0|) )*   )/x
3975    abcd
3976
3977/(  (?(1)0|)*   )/x
3978    abcd
3979
3980/[[:abcd:xyz]]/
3981    a]
3982    :]
3983
3984/[abc[:x\]pqr]/
3985    a
3986    [
3987    :
3988    ]
3989    p
3990
3991/.*[op][xyz]/
3992\= Expect no match
3993    fooabcfoo
3994
3995/(?(?=.*b)b|^)/
3996   adc
3997   abc
3998
3999/(?(?=^.*b)b|^)/
4000   adc
4001\= Expect no match
4002   abc
4003
4004/(?(?=.*b)b|^)*/
4005   adc
4006   abc
4007
4008/(?(?=.*b)b|^)+/
4009   adc
4010   abc
4011
4012/(?(?=b).*b|^d)/
4013    abc
4014
4015/(?(?=.*b).*b|^d)/
4016    abc
4017
4018/^%((?(?=[a])[^%])|b)*%$/
4019    %ab%
4020
4021/(?i)a(?-i)b|c/
4022    XabX
4023    XAbX
4024    CcC
4025\= Expect no match
4026    XABX
4027
4028/[\x00-\xff\s]+/
4029    \x0a\x0b\x0c\x0d
4030
4031/(abc)\1/i
4032\= Expect no match
4033   abc
4034
4035/(abc)\1/
4036\= Expect no match
4037   abc
4038
4039/[^a]*/i
4040    12abc
4041    12ABC
4042
4043/[^a]*+/i
4044    12abc
4045    12ABC
4046
4047/[^a]*?X/i
4048\= Expect no match
4049    12abc
4050    12ABC
4051
4052/[^a]+?X/i
4053\= Expect no match
4054    12abc
4055    12ABC
4056
4057/[^a]?X/i
4058    12aXbcX
4059    12AXBCX
4060    BCX
4061
4062/[^a]??X/i
4063    12aXbcX
4064    12AXBCX
4065    BCX
4066
4067/[^a]?+X/i
4068    12aXbcX
4069    12AXBCX
4070    BCX
4071
4072/[^a]{2,3}/i
4073    abcdef
4074    ABCDEF
4075
4076/[^a]{2,3}?/i
4077    abcdef
4078    ABCDEF
4079
4080/[^a]{2,3}+/i
4081    abcdef
4082    ABCDEF
4083
4084/((a|)+)+Z/
4085    Z
4086
4087/(a)b|(a)c/
4088    ac
4089
4090/(?>(a))b|(a)c/
4091    ac
4092
4093/(?=(a))ab|(a)c/
4094    ac
4095
4096/((?>(a))b|(a)c)/
4097    ac
4098
4099/((?>(a))b|(a)c)++/
4100    ac
4101
4102/(?:(?>(a))b|(a)c)++/
4103    ac
4104
4105/(?=(?>(a))b|(a)c)(..)/
4106    ac
4107
4108/(?>(?>(a))b|(a)c)/
4109    ac
4110
4111/(?:(?>([ab])))+a=/aftertext
4112    =ba=
4113
4114/(?>([ab]))+a=/aftertext
4115    =ba=
4116
4117/((?>(a+)b)+(aabab))/
4118    aaaabaaabaabab
4119
4120/(?>a+|ab)+?c/
4121\= Expect no match
4122    aabc
4123
4124/(?>a+|ab)+c/
4125\= Expect no match
4126    aabc
4127
4128/(?:a+|ab)+c/
4129    aabc
4130
4131/(?(?=(a))a)/
4132    a
4133
4134/(?(?=(a))a)(b)/
4135    ab
4136
4137/^(?:a|ab)++c/
4138\= Expect no match
4139    aaaabc
4140
4141/^(?>a|ab)++c/
4142\= Expect no match
4143    aaaabc
4144
4145/^(?:a|ab)+c/
4146    aaaabc
4147
4148/(?=abc){3}abc/aftertext
4149    abcabcabc
4150\= Expect no match
4151    xyz
4152
4153/(?=abc)+abc/aftertext
4154    abcabcabc
4155\= Expect no match
4156    xyz
4157
4158/(?=abc)++abc/aftertext
4159    abcabcabc
4160\= Expect no match
4161    xyz
4162
4163/(?=abc){0}xyz/
4164    xyz
4165
4166/(?=abc){1}xyz/
4167\= Expect no match
4168    xyz
4169
4170/(?=(a))?./
4171    ab
4172    bc
4173
4174/(?=(a))??./
4175    ab
4176    bc
4177
4178/^(?=(?1))?[az]([abc])d/
4179    abd
4180    zcdxx
4181
4182/^(?!a){0}\w+/
4183    aaaaa
4184
4185/(?<=(abc))?xyz/
4186    abcxyz
4187    pqrxyz
4188
4189/^[\g<a>]+/
4190    ggg<<<aaa>>>
4191\= Expect no match
4192    \\ga
4193
4194/^[\ga]+/
4195    gggagagaxyz
4196
4197/^[:a[:digit:]]+/
4198    aaaa444:::Z
4199
4200/^[:a[:digit:]:b]+/
4201    aaaa444:::bbbZ
4202
4203/[:a]xxx[b:]/
4204     :xxx:
4205
4206/(?<=a{2})b/i
4207    xaabc
4208\= Expect no match
4209    xabc
4210
4211/(?<!a{2})b/i
4212    xabc
4213\= Expect no match
4214    xaabc
4215
4216/(?<=a\h)c/
4217    xa c
4218
4219/(?<=[^a]{2})b/
4220    axxbc
4221    aAAbc
4222\= Expect no match
4223    xaabc
4224
4225/(?<=[^a]{2})b/i
4226    axxbc
4227\= Expect no match
4228    aAAbc
4229    xaabc
4230
4231/(?<=a\H)c/
4232    abc
4233
4234/(?<=a\V)c/
4235    abc
4236
4237/(?<=a\v)c/
4238    a\nc
4239
4240/(?(?=c)c|d)++Y/
4241    XcccddYX
4242
4243/(?(?=c)c|d)*+Y/
4244    XcccddYX
4245
4246/^(a{2,3}){2,}+a/
4247    aaaaaaa
4248\= Expect no match
4249    aaaaaa
4250    aaaaaaaaa
4251
4252/^(a{2,3})++a/
4253\= Expect no match
4254    aaaaaa
4255
4256/^(a{2,3})*+a/
4257\= Expect no match
4258    aaaaaa
4259
4260/\H\h\V\v/
4261    X X\x0a
4262    X\x09X\x0b
4263\= Expect no match
4264    \xa0 X\x0a
4265
4266/\H*\h+\V?\v{3,4}/
4267    \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
4268    \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
4269    \x09\x20\xa0\x0a\x0b\x0c
4270\= Expect no match
4271    \x09\x20\xa0\x0a\x0b
4272
4273/\H{3,4}/
4274    XY  ABCDE
4275    XY  PQR ST
4276
4277/.\h{3,4}./
4278    XY  AB    PQRS
4279
4280/\h*X\h?\H+Y\H?Z/
4281    >XNNNYZ
4282    >  X NYQZ
4283\= Expect no match
4284    >XYZ
4285    >  X NY Z
4286
4287/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
4288    >XY\x0aZ\x0aA\x0bNN\x0c
4289    >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
4290
4291/(foo)\Kbar/
4292    foobar
4293
4294/(foo)(\Kbar|baz)/
4295    foobar
4296    foobaz
4297
4298/(foo\Kbar)baz/
4299    foobarbaz
4300
4301/abc\K|def\K/g,aftertext
4302    Xabcdefghi
4303
4304/ab\Kc|de\Kf/g,aftertext
4305    Xabcdefghi
4306
4307/(?=C)/g,aftertext
4308    ABCDECBA
4309
4310/^abc\K/aftertext
4311    abcdef
4312\= Expect no match
4313    defabcxyz
4314
4315/^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-2}Z/
4316    ababababbbabZXXXX
4317
4318/(?<A>tom|bon)-\g{A}/
4319    tom-tom
4320    bon-bon
4321
4322/(^(a|b\g{-1}))/
4323\= Expect no match
4324    bacxxx
4325
4326/(?|(abc)|(xyz))\1/
4327    abcabc
4328    xyzxyz
4329\= Expect no match
4330    abcxyz
4331    xyzabc
4332
4333/(?|(abc)|(xyz))(?1)/
4334    abcabc
4335    xyzabc
4336\= Expect no match
4337    xyzxyz
4338
4339/^X(?5)(a)(?|(b)|(q))(c)(d)(Y)/
4340    XYabcdY
4341
4342/^X(?7)(a)(?|(b|(r)(s))|(q))(c)(d)(Y)/
4343    XYabcdY
4344
4345/^X(?7)(a)(?|(b|(?|(r)|(t))(s))|(q))(c)(d)(Y)/
4346    XYabcdY
4347
4348/(?'abc'\w+):\k<abc>{2}/
4349    a:aaxyz
4350    ab:ababxyz
4351\= Expect no match
4352    a:axyz
4353    ab:abxyz
4354
4355/(?'abc'\w+):\g{abc}{2}/
4356    a:aaxyz
4357    ab:ababxyz
4358\= Expect no match
4359    a:axyz
4360    ab:abxyz
4361
4362/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
4363    abd
4364    ce
4365
4366/^(a.)\g-1Z/
4367    aXaXZ
4368
4369/^(a.)\g{-1}Z/
4370    aXaXZ
4371
4372/^(?(DEFINE) (?<A> a) (?<B> b) )  (?&A) (?&B) /x
4373    abcd
4374
4375/(?<all>(?:(?:a(?&all))|(b))(c?))/
4376    aabc
4377
4378/(a(b)|(c))(?1)/
4379    abc
4380    cab
4381
4382/(?1)(a(b)|(c))/
4383    abc
4384    cab
4385
4386/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
4387  (?(DEFINE)
4388  (?<NAME_PAT>[a-z]+)
4389  (?<ADDRESS_PAT>\d+)
4390  )/x
4391    metcalfe 33
4392
4393/(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
4394    1.2.3.4
4395    131.111.10.206
4396    10.0.0.0
4397\= Expect no match
4398    10.6
4399    455.3.4.5
4400
4401/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
4402    1.2.3.4
4403    131.111.10.206
4404    10.0.0.0
4405\= Expect no match
4406    10.6
4407    455.3.4.5
4408
4409/^(\w++|\s++)*$/
4410    now is the time for all good men to come to the aid of the party
4411\= Expect no match
4412    this is not a line with only words and spaces!
4413
4414/(\d++)(\w)/
4415    12345a
4416\= Expect no match
4417    12345+
4418
4419/a++b/
4420    aaab
4421
4422/(a++b)/
4423    aaab
4424
4425/(a++)b/
4426    aaab
4427
4428/([^()]++|\([^()]*\))+/
4429    ((abc(ade)ufh()()x
4430
4431/\(([^()]++|\([^()]+\))+\)/
4432    (abc)
4433    (abc(def)xyz)
4434\= Expect no match
4435    ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4436
4437/^([^()]|\((?1)*\))*$/
4438    abc
4439    a(b)c
4440    a(b(c))d
4441\= Expect no match)
4442    a(b(c)d
4443
4444/^>abc>([^()]|\((?1)*\))*<xyz<$/
4445   >abc>123<xyz<
4446   >abc>1(2)3<xyz<
4447   >abc>(1(2)3)<xyz<
4448
4449/^(?:((.)(?1)\2|)|((.)(?3)\4|.))$/i
4450    1221
4451    Satanoscillatemymetallicsonatas
4452    AmanaplanacanalPanama
4453    AblewasIereIsawElba
4454\= Expect no match
4455    Thequickbrownfox
4456
4457/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/
4458    12
4459    (((2+2)*-3)-7)
4460    -12
4461\= Expect no match
4462    ((2+2)*-3)-7)
4463
4464/^(x(y|(?1){2})z)/
4465    xyz
4466    xxyzxyzz
4467\= Expect no match
4468    xxyzz
4469    xxyzxyzxyzz
4470
4471/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/x
4472    <>
4473    <abcd>
4474    <abc <123> hij>
4475    <abc <def> hij>
4476    <abc<>def>
4477    <abc<>
4478\= Expect no match
4479    <abc
4480
4481/^a+(*FAIL)/
4482\= Expect no match
4483    aaaaaa
4484
4485/a+b?c+(*FAIL)/
4486\= Expect no match
4487    aaabccc
4488
4489/a+b?(*PRUNE)c+(*FAIL)/
4490\= Expect no match
4491    aaabccc
4492
4493/a+b?(*COMMIT)c+(*FAIL)/
4494\= Expect no match
4495    aaabccc
4496
4497/a+b?(*SKIP)c+(*FAIL)/
4498\= Expect no match
4499    aaabcccaaabccc
4500
4501/^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
4502    aaaxxxxxx
4503    aaa++++++
4504    bbbxxxxx
4505    bbb+++++
4506    cccxxxx
4507    ccc++++
4508    dddddddd
4509
4510/^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
4511    aaaxxxxxx
4512    aaa++++++
4513    bbbxxxxx
4514    bbb+++++
4515    cccxxxx
4516    ccc++++
4517    dddddddd
4518
4519/a+b?(*THEN)c+(*FAIL)/
4520\= Expect no match
4521    aaabccc
4522
4523/(A (A|B(*ACCEPT)|C) D)(E)/x
4524    AB
4525    ABX
4526    AADE
4527    ACDE
4528\= Expect no match
4529    AD
4530
4531/^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$/i
4532    1221
4533    Satan, oscillate my metallic sonatas!
4534    A man, a plan, a canal: Panama!
4535    Able was I ere I saw Elba.
4536\= Expect no match
4537    The quick brown fox
4538
4539/^((.)(?1)\2|.)$/
4540    a
4541    aba
4542    aabaa
4543    abcdcba
4544    pqaabaaqp
4545    ablewasiereisawelba
4546\= Expect no match
4547    rhubarb
4548    the quick brown fox
4549
4550/(a)(?<=b(?1))/
4551    baz
4552\= Expect no match
4553    caz
4554
4555/(?<=b(?1))(a)/
4556    zbaaz
4557\= Expect no match
4558    aaa
4559
4560/(?<X>a)(?<=b(?&X))/
4561    baz
4562
4563/^(?|(abc)|(def))\1/
4564    abcabc
4565    defdef
4566\= Expect no match
4567    abcdef
4568    defabc
4569
4570/^(?|(abc)|(def))(?1)/
4571    abcabc
4572    defabc
4573\= Expect no match
4574    defdef
4575    abcdef
4576
4577/(?:a(?<quote> (?<apostrophe>')|(?<realquote>")) |b(?<quote> (?<apostrophe>')|(?<realquote>")) ) (?('quote')[a-z]+|[0-9]+)/x,dupnames
4578    a\"aaaaa
4579    b\"aaaaa
4580\= Expect no match
4581    b\"11111
4582
4583/(?:(?1)|B)(A(*F)|C)/
4584    ABCD
4585    CCD
4586\= Expect no match
4587    CAD
4588
4589/^(?:(?1)|B)(A(*F)|C)/
4590    CCD
4591    BCD
4592\= Expect no match
4593    ABCD
4594    CAD
4595    BAD
4596
4597/(?:(?1)|B)(A(*ACCEPT)XX|C)D/
4598    AAD
4599    ACD
4600    BAD
4601    BCD
4602    BAX
4603\= Expect no match
4604    ACX
4605    ABC
4606
4607/(?(DEFINE)(A))B(?1)C/
4608    BAC
4609
4610/(?(DEFINE)((A)\2))B(?1)C/
4611    BAAC
4612
4613/(?<pn> \( ( [^()]++ | (?&pn) )* \) )/x
4614    (ab(cd)ef)
4615
4616/^(?=a(*SKIP)b|ac)/
4617\= Expect no match
4618    ac
4619
4620/^(?=a(*PRUNE)b)/
4621    ab
4622\= Expect no match
4623    ac
4624
4625/^(?=a(*ACCEPT)b)/
4626    ac
4627
4628/(?>a\Kb)/
4629    ab
4630
4631/((?>a\Kb))/
4632    ab
4633
4634/(a\Kb)/
4635    ab
4636
4637/^a\Kcz|ac/
4638    ac
4639
4640/(?>a\Kbz|ab)/
4641    ab
4642
4643/^(?&t)(?(DEFINE)(?<t>a\Kb))$/
4644    ab
4645
4646/^([^()]|\((?1)*\))*$/
4647    a(b)c
4648    a(b(c)d)e
4649
4650/(?P<L1>(?P<L2>0)(?P>L1)|(?P>L2))/
4651    0
4652    00
4653    0000
4654
4655/(?P<L1>(?P<L2>0)|(?P>L2)(?P>L1))/
4656    0
4657    00
4658    0000
4659
4660# This one does fail, as expected, in Perl. It needs the complex item at the
4661# end of the pattern. A single letter instead of (B|D) makes it not fail, which
4662# I think is a Perl bug.
4663
4664/A(*COMMIT)(B|D)/
4665\= Expect no match
4666    ACABX
4667
4668# Check the use of names for failure
4669
4670/^(A(*PRUNE:A)B|C(*PRUNE:B)D)/mark
4671\= Expect no match
4672    AC
4673    CB
4674
4675/(*MARK:A)(*SKIP:B)(C|X)/mark
4676    C
4677\= Expect no match
4678    D
4679
4680/^(A(*THEN:A)B|C(*THEN:B)D)/mark
4681\= Expect no match
4682    CB
4683
4684/^(?:A(*THEN:A)B|C(*THEN:B)D)/mark
4685\= Expect no match
4686    CB
4687
4688/^(?>A(*THEN:A)B|C(*THEN:B)D)/mark
4689\= Expect no match
4690    CB
4691
4692# This should succeed, as the skip causes bump to offset 1 (the mark). Note
4693# that we have to have something complicated such as (B|Z) at the end because,
4694# for Perl, a simple character somehow causes an unwanted optimization to mess
4695# with the handling of backtracking verbs.
4696
4697/A(*MARK:A)A+(*SKIP:A)(B|Z) | AC/x,mark
4698    AAAC
4699
4700# Test skipping over a non-matching mark.
4701
4702/A(*MARK:A)A+(*MARK:B)(*SKIP:A)(B|Z) | AC/x,mark
4703    AAAC
4704
4705# Check shorthand for MARK.
4706
4707/A(*:A)A+(*SKIP:A)(B|Z) | AC/x,mark
4708    AAAC
4709
4710/(*:A)A+(*SKIP:A)(B|Z)/mark
4711\= Expect no match
4712    AAAC
4713
4714# This should succeed, as a non-existent skip name disables the skip.
4715
4716/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/x,mark
4717    AAAC
4718
4719/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC(*:B)/x,mark
4720    AAAC
4721
4722# COMMIT at the start of a pattern should act like an anchor. Again, however,
4723# we need the complication for Perl.
4724
4725/(*COMMIT)(A|P)(B|P)(C|P)/
4726    ABCDEFG
4727\= Expect no match
4728    DEFGABC
4729
4730# COMMIT inside an atomic group can't stop backtracking over the group.
4731
4732/(\w+)(?>b(*COMMIT))\w{2}/
4733    abbb
4734
4735/(\w+)b(*COMMIT)\w{2}/
4736\= Expect no match
4737    abbb
4738
4739# Check opening parens in comment when seeking forward reference.
4740
4741/(?&t)(?#()(?(DEFINE)(?<t>a))/
4742    bac
4743
4744# COMMIT should override THEN.
4745
4746/(?>(*COMMIT)(?>yes|no)(*THEN)(*F))?/
4747\= Expect no match
4748  yes
4749
4750/(?>(*COMMIT)(yes|no)(*THEN)(*F))?/
4751\= Expect no match
4752  yes
4753
4754/b?(*SKIP)c/
4755    bc
4756    abc
4757
4758/(*SKIP)bc/
4759\= Expect no match
4760    a
4761
4762/(*SKIP)b/
4763\= Expect no match
4764    a
4765
4766/(?P<abn>(?P=abn)xxx|)+/
4767    xxx
4768
4769/(?i:([^b]))(?1)/
4770    aa
4771    aA
4772\= Expect no match
4773    ab
4774    aB
4775    Ba
4776    ba
4777
4778/^(?&t)*+(?(DEFINE)(?<t>a))\w$/
4779    aaaaaaX
4780\= Expect no match
4781    aaaaaa
4782
4783/^(?&t)*(?(DEFINE)(?<t>a))\w$/
4784    aaaaaaX
4785    aaaaaa
4786
4787/^(a)*+(\w)/
4788    aaaaX
4789    YZ
4790\= Expect no match
4791    aaaa
4792
4793/^(?:a)*+(\w)/
4794    aaaaX
4795    YZ
4796\= Expect no match
4797    aaaa
4798
4799/^(a)++(\w)/
4800    aaaaX
4801\= Expect no match
4802    aaaa
4803    YZ
4804
4805/^(?:a)++(\w)/
4806    aaaaX
4807\= Expect no match
4808    aaaa
4809    YZ
4810
4811/^(a)?+(\w)/
4812    aaaaX
4813    YZ
4814
4815/^(?:a)?+(\w)/
4816    aaaaX
4817    YZ
4818
4819/^(a){2,}+(\w)/
4820    aaaaX
4821\= Expect no match
4822    aaa
4823    YZ
4824
4825/^(?:a){2,}+(\w)/
4826    aaaaX
4827\= Expect no match
4828    aaa
4829    YZ
4830
4831/(a|)*(?1)b/
4832    b
4833    ab
4834    aab
4835
4836/(a)++(?1)b/
4837\= Expect no match
4838    ab
4839    aab
4840
4841/(a)*+(?1)b/
4842\= Expect no match
4843    ab
4844    aab
4845
4846/(?1)(?:(b)){0}/
4847    b
4848
4849/(foo ( \( ((?:(?> [^()]+ )|(?2))*) \) ) )/x
4850    foo(bar(baz)+baz(bop))
4851
4852/(A (A|B(*ACCEPT)|C) D)(E)/x
4853    AB
4854
4855/\A.*?(a|bc)/
4856    ba
4857
4858/\A.*?(?:a|bc)++/
4859    ba
4860
4861/\A.*?(a|bc)++/
4862    ba
4863
4864/\A.*?(?:a|bc|d)/
4865    ba
4866
4867/(?:(b))++/
4868    beetle
4869
4870/(?(?=(a(*ACCEPT)z))a)/
4871    a
4872
4873/^(a)(?1)+ab/
4874    aaaab
4875
4876/^(a)(?1)++ab/
4877\= Expect no match
4878    aaaab
4879
4880/^(?=a(*:M))aZ/mark
4881    aZbc
4882
4883/^(?!(*:M)b)aZ/mark
4884    aZbc
4885
4886/(?(DEFINE)(a))?b(?1)/
4887    backgammon
4888
4889/^\N+/
4890    abc\ndef
4891
4892/^\N{1,}/
4893    abc\ndef
4894
4895/(?(R)a+|(?R)b)/
4896    aaaabcde
4897
4898/(?(R)a+|((?R))b)/
4899    aaaabcde
4900
4901/((?(R)a+|(?1)b))/
4902    aaaabcde
4903
4904/((?(R1)a+|(?1)b))/
4905    aaaabcde
4906
4907/((?(R)a|(?1)))*/
4908    aaa
4909
4910/((?(R)a|(?1)))+/
4911    aaa
4912
4913/a(*:any
4914name)/mark
4915    abc
4916
4917/(?>(?&t)c|(?&t))(?(DEFINE)(?<t>a|b(*PRUNE)c))/
4918    a
4919    ba
4920    bba
4921
4922# Checking revised (*THEN) handling.
4923
4924# Capture
4925
4926/^.*? (a(*THEN)b) c/x
4927\= Expect no match
4928    aabc
4929
4930/^.*? (a(*THEN)b|(*F)) c/x
4931    aabc
4932
4933/^.*? ( (a(*THEN)b) | (*F) ) c/x
4934    aabc
4935
4936/^.*? ( (a(*THEN)b) ) c/x
4937\= Expect no match
4938    aabc
4939
4940# Non-capture
4941
4942/^.*? (?:a(*THEN)b) c/x
4943\= Expect no match
4944    aabc
4945
4946/^.*? (?:a(*THEN)b|(*F)) c/x
4947    aabc
4948
4949/^.*? (?: (?:a(*THEN)b) | (*F) ) c/x
4950    aabc
4951
4952/^.*? (?: (?:a(*THEN)b) ) c/x
4953\= Expect no match
4954    aabc
4955
4956# Atomic
4957
4958/^.*? (?>a(*THEN)b) c/x
4959\= Expect no match
4960    aabc
4961
4962/^.*? (?>a(*THEN)b|(*F)) c/x
4963    aabc
4964
4965/^.*? (?> (?>a(*THEN)b) | (*F) ) c/x
4966    aabc
4967
4968/^.*? (?> (?>a(*THEN)b) ) c/x
4969\= Expect no match
4970    aabc
4971
4972# Possessive capture
4973
4974/^.*? (a(*THEN)b)++ c/x
4975\= Expect no match
4976    aabc
4977
4978/^.*? (a(*THEN)b|(*F))++ c/x
4979    aabc
4980
4981/^.*? ( (a(*THEN)b)++ | (*F) )++ c/x
4982    aabc
4983
4984/^.*? ( (a(*THEN)b)++ )++ c/x
4985\= Expect no match
4986    aabc
4987
4988# Possessive non-capture
4989
4990/^.*? (?:a(*THEN)b)++ c/x
4991\= Expect no match
4992    aabc
4993
4994/^.*? (?:a(*THEN)b|(*F))++ c/x
4995    aabc
4996
4997/^.*? (?: (?:a(*THEN)b)++ | (*F) )++ c/x
4998    aabc
4999
5000/^.*? (?: (?:a(*THEN)b)++ )++ c/x
5001\= Expect no match
5002    aabc
5003
5004# Condition assertion
5005
5006/^(?(?=a(*THEN)b)ab|ac)/
5007    ac
5008
5009# Condition
5010
5011/^.*?(?(?=a)a|b(*THEN)c)/
5012\= Expect no match
5013    ba
5014
5015/^.*?(?:(?(?=a)a|b(*THEN)c)|d)/
5016    ba
5017
5018/^.*?(?(?=a)a(*THEN)b|c)/
5019\= Expect no match
5020    ac
5021
5022# Assertion
5023
5024/^.*(?=a(*THEN)b)/
5025    aabc
5026
5027# --------------------------
5028
5029/(?>a(*:m))/imsx,mark
5030    a
5031
5032/(?>(a)(*:m))/imsx,mark
5033    a
5034
5035/(?<=a(*ACCEPT)b)c/
5036    xacd
5037
5038/(?<=(a(*ACCEPT)b))c/
5039    xacd
5040
5041/(?<=(a(*COMMIT)b))c/
5042    xabcd
5043\= Expect no match
5044    xacd
5045
5046/(?<!a(*FAIL)b)c/
5047    xcd
5048    acd
5049
5050/(?<=a(*:N)b)c/mark
5051    xabcd
5052
5053/(?<=a(*PRUNE)b)c/
5054    xabcd
5055
5056/(?<=a(*SKIP)b)c/
5057    xabcd
5058
5059/(?<=a(*THEN)b)c/
5060    xabcd
5061
5062/(a)(?2){2}(.)/
5063    abcd
5064
5065/(*MARK:A)(*PRUNE:B)(C|X)/mark
5066    C
5067\= Expect no match
5068    D
5069
5070/(*MARK:A)(*PRUNE:B)(C|X)/mark
5071    C
5072\= Expect no match
5073    D
5074
5075/(*MARK:A)(*THEN:B)(C|X)/mark
5076    C
5077\= Expect no match
5078    D
5079
5080/(*MARK:A)(*THEN:B)(C|X)/mark,no_start_optimize
5081    C
5082\= Expect no match
5083    D
5084
5085/(*MARK:A)(*THEN:B)(C|X)/mark
5086    C
5087\= Expect no match
5088    D
5089
5090# This should fail, as the skip causes a bump to offset 3 (the skip).
5091
5092/A(*MARK:A)A+(*SKIP)(B|Z) | AC/x,mark
5093\= Expect no match
5094    AAAC
5095
5096# Same
5097
5098/A(*MARK:A)A+(*MARK:B)(*SKIP:B)(B|Z) | AC/x,mark
5099\= Expect no match
5100    AAAC
5101
5102/A(*:A)A+(*SKIP)(B|Z) | AC/x,mark
5103\= Expect no match
5104    AAAC
5105
5106# This should fail, as a null name is the same as no name.
5107
5108/A(*MARK:A)A+(*SKIP:)(B|Z) | AC/x,mark
5109\= Expect no match
5110    AAAC
5111
5112# A check on what happens after hitting a mark and them bumping along to
5113# something that does not even start. Perl reports tags after the failures
5114# here, though it does not when the individual letters are made into something
5115# more complicated.
5116
5117/A(*:A)B|XX(*:B)Y/mark
5118    AABC
5119    XXYZ
5120\= Expect no match
5121    XAQQ
5122    XAQQXZZ
5123    AXQQQ
5124    AXXQQQ
5125
5126/^(A(*THEN:A)B|C(*THEN:B)D)/mark
5127    AB
5128    CD
5129\= Expect no match
5130    AC
5131    CB
5132
5133/^(A(*PRUNE:A)B|C(*PRUNE:B)D)/mark
5134    AB
5135    CD
5136\= Expect no match
5137    AC
5138    CB
5139
5140# An empty name does not pass back an empty string. It is the same as if no
5141# name were given.
5142
5143/^(A(*PRUNE:)B|C(*PRUNE:B)D)/mark
5144    AB
5145    CD
5146
5147# PRUNE goes to next bumpalong; COMMIT does not.
5148
5149/A(*PRUNE:A)B/mark
5150    ACAB
5151
5152# Mark names can be duplicated.
5153
5154/A(*:A)B|X(*:A)Y/mark
5155    AABC
5156    XXYZ
5157
5158/b(*:m)f|a(*:n)w/mark
5159    aw
5160\= Expect no match
5161    abc
5162
5163/b(*:m)f|aw/mark
5164    abaw
5165\= Expect no match
5166    abc
5167    abax
5168
5169/A(*MARK:A)A+(*SKIP:B)(B|Z) | AAC/x,mark
5170    AAAC
5171
5172/(?=a(*MARK:A)b)..x/mark
5173    abxy
5174\= Expect no match
5175    abpq
5176
5177/(?=a(*MARK:A)b)..(*:Y)x/mark
5178    abxy
5179\= Expect no match
5180    abpq
5181
5182/(?=a(*PRUNE:A)b)..x/mark
5183    abxy
5184\= Expect no match
5185    abpq
5186
5187/(?=a(*PRUNE:A)b)..(*:Y)x/mark
5188    abxy
5189\= Expect no match
5190    abpq
5191
5192/(?=a(*THEN:A)b)..x/mark
5193    abxy
5194\= Expect no match
5195    abpq
5196
5197/(?=a(*THEN:A)b)..(*:Y)x/mark
5198    abxy
5199\= Expect no match
5200    abpq
5201
5202/(another)?(\1?)test/
5203    hello world test
5204
5205/(another)?(\1+)test/
5206\= Expect no match
5207    hello world test
5208
5209/(a(*COMMIT)b){0}a(?1)|aac/
5210    aac
5211
5212/((?:a?)*)*c/
5213    aac
5214
5215/((?>a?)*)*c/
5216    aac
5217
5218/(?>.*?a)(?<=ba)/
5219    aba
5220
5221/(?:.*?a)(?<=ba)/
5222    aba
5223
5224/(?>.*?a)b/s
5225    aab
5226
5227/(?>.*?a)b/
5228    aab
5229
5230/(?>^a)b/s
5231\= Expect no match
5232    aab
5233
5234/(?>.*?)(?<=(abcd)|(wxyz))/
5235    alphabetabcd
5236    endingwxyz
5237
5238/(?>.*)(?<=(abcd)|(wxyz))/
5239    alphabetabcd
5240    endingwxyz
5241
5242/(?>.*)foo/
5243\= Expect no match
5244    abcdfooxyz
5245
5246/(?>.*?)foo/
5247    abcdfooxyz
5248
5249/(?:(a(*PRUNE)b)){0}(?:(?1)|ac)/
5250    ac
5251
5252/(?:(a(*SKIP)b)){0}(?:(?1)|ac)/
5253    ac
5254
5255/(?<=(*SKIP)ac)a/
5256\= Expect no match
5257    aa
5258
5259/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/x,mark
5260    AAAC
5261
5262/a(*SKIP:m)x|ac(*:n)(*SKIP:n)d|ac/mark
5263    acacd
5264
5265/A(*SKIP:m)x|A(*SKIP:n)x|AB/mark
5266    AB
5267
5268/((*SKIP:r)d){0}a(*SKIP:m)x|ac(*:n)|ac/mark
5269    acacd
5270
5271# Tests that try to figure out how Perl works. My hypothesis is that the first
5272# verb that is backtracked onto is the one that acts. This seems to be the case
5273# almost all the time, but there is one exception that is perhaps a bug.
5274
5275# This matches "aaaac"; each PRUNE advances one character until the subject no
5276# longer starts with 5 'a's.
5277
5278/aaaaa(*PRUNE)b|a+c/
5279    aaaaaac
5280
5281# Putting SKIP in front of PRUNE makes no difference, as it is never
5282# backtracked onto, whether or not it has a label.
5283
5284/aaaaa(*SKIP)(*PRUNE)b|a+c/
5285    aaaaaac
5286
5287/aaaaa(*SKIP:N)(*PRUNE)b|a+c/
5288    aaaaaac
5289
5290/aaaa(*:N)a(*SKIP:N)(*PRUNE)b|a+c/
5291    aaaaaac
5292
5293# Putting THEN in front makes no difference.
5294
5295/aaaaa(*THEN)(*PRUNE)b|a+c/
5296    aaaaaac
5297
5298# However, putting COMMIT in front of the prune changes it to "no match". I
5299# think this is inconsistent and possibly a bug. For the moment, running this
5300# test is moved out of the Perl-compatible file.
5301
5302/aaaaa(*COMMIT)(*PRUNE)b|a+c/
5303
5304# OK, lets play the same game again using SKIP instead of PRUNE.
5305
5306# This matches "ac" because SKIP forces the next match to start on the
5307# sixth "a".
5308
5309/aaaaa(*SKIP)b|a+c/
5310    aaaaaac
5311
5312# Putting PRUNE in front makes no difference.
5313
5314/aaaaa(*PRUNE)(*SKIP)b|a+c/
5315    aaaaaac
5316
5317# Putting THEN in front makes no difference.
5318
5319/aaaaa(*THEN)(*SKIP)b|a+c/
5320    aaaaaac
5321
5322# In this case, neither does COMMIT. This still matches "ac".
5323
5324/aaaaa(*COMMIT)(*SKIP)b|a+c/
5325    aaaaaac
5326
5327# This gives "no match", as expected.
5328
5329/aaaaa(*COMMIT)b|a+c/
5330\= Expect no match
5331    aaaaaac
5332
5333# ---- Tests using THEN ----
5334
5335# This matches "aaaaaac", as expected.
5336
5337/aaaaa(*THEN)b|a+c/
5338    aaaaaac
5339
5340# Putting SKIP in front makes no difference.
5341
5342/aaaaa(*SKIP)(*THEN)b|a+c/
5343    aaaaaac
5344
5345# Putting PRUNE in front makes no difference.
5346
5347/aaaaa(*PRUNE)(*THEN)b|a+c/
5348    aaaaaac
5349
5350# Putting COMMIT in front makes no difference.
5351
5352/aaaaa(*COMMIT)(*THEN)b|a+c/
5353    aaaaaac
5354
5355# End of "priority" tests
5356
5357/aaaaa(*:m)(*PRUNE:m)(*SKIP:m)m|a+/
5358    aaaaaa
5359
5360/aaaaa(*:m)(*MARK:m)(*PRUNE)(*SKIP:m)m|a+/
5361    aaaaaa
5362
5363/aaaaa(*:n)(*PRUNE:m)(*SKIP:m)m|a+/
5364    aaaaaa
5365
5366/aaaaa(*:n)(*MARK:m)(*PRUNE)(*SKIP:m)m|a+/
5367    aaaaaa
5368
5369/a(*MARK:A)aa(*PRUNE:A)a(*SKIP:A)b|a+c/
5370    aaaac
5371
5372/a(*MARK:A)aa(*MARK:A)a(*SKIP:A)b|a+c/
5373    aaaac
5374
5375/aaa(*PRUNE:A)a(*SKIP:A)b|a+c/
5376    aaaac
5377
5378/aaa(*MARK:A)a(*SKIP:A)b|a+c/
5379    aaaac
5380
5381/a(*:m)a(*COMMIT)(*SKIP:m)b|a+c/mark
5382    aaaaaac
5383
5384/.?(a|b(*THEN)c)/
5385    ba
5386
5387/(a(*COMMIT)b)c|abd/
5388    abc
5389\= Expect no match
5390    abd
5391
5392/(?=a(*COMMIT)b)abc|abd/
5393    abc
5394    abd
5395
5396/(?>a(*COMMIT)b)c|abd/
5397    abc
5398    abd
5399
5400/a(?=b(*COMMIT)c)[^d]|abd/
5401    abc
5402\= Expect no match
5403    abd
5404
5405/a(?=bc).|abd/
5406    abd
5407    abc
5408
5409/a(?>b(*COMMIT)c)d|abd/
5410\= Expect no match
5411    abceabd
5412
5413/a(?>bc)d|abd/
5414    abceabd
5415
5416/(?>a(*COMMIT)b)c|abd/
5417    abd
5418
5419/(?>a(*COMMIT)c)d|abd/
5420\= Expect no match
5421    abd
5422
5423/((?=a(*COMMIT)b)ab|ac){0}(?:(?1)|a(c))/
5424    ac
5425
5426# These tests were formerly in test 2, but changes in PCRE and Perl have
5427# made them compatible.
5428
5429/^(a)?(?(1)a|b)+$/
5430\= Expect no match
5431    a
5432
5433/A(*PRUNE:A)A+(*SKIP:A)(B|Z) | AC/x,mark
5434\= Expect no match
5435    AAAC
5436
5437/^((abc|abcx)(*THEN)y|abcd)/
5438    abcd
5439\= Expect no match
5440    abcxy
5441
5442/^((yes|no)(*THEN)(*F))?/
5443\= Expect no match
5444    yes
5445
5446/(A (.*)   C? (*THEN)  | A D) (*FAIL)/x
5447\= Expect no match
5448    AbcdCBefgBhiBqz
5449
5450/(A (.*)   C? (*THEN)  | A D) z/x
5451\= Expect no match
5452    AbcdCBefgBhiBqz
5453
5454/(A (.*)   C? (*THEN)  | A D) \s* (*FAIL)/x
5455\= Expect no match
5456    AbcdCBefgBhiBqz
5457
5458/(A (.*)   C? (*THEN)  | A D) \s* z/x
5459\= Expect no match
5460    AbcdCBefgBhiBqz
5461
5462/(A (.*)   (?:C|) (*THEN)  | A D) (*FAIL)/x
5463\= Expect no match
5464    AbcdCBefgBhiBqz
5465
5466/(A (.*)   (?:C|) (*THEN)  | A D) z/x
5467\= Expect no match
5468    AbcdCBefgBhiBqz
5469
5470/(A (.*)   C{0,6} (*THEN)  | A D) (*FAIL)/x
5471\= Expect no match
5472    AbcdCBefgBhiBqz
5473
5474/(A (.*)   C{0,6} (*THEN)  | A D) z/x
5475\= Expect no match
5476    AbcdCBefgBhiBqz
5477
5478/(A (.*)   (CE){0,6} (*THEN)  | A D) (*FAIL)/x
5479\= Expect no match
5480    AbcdCEBefgBhiBqz
5481
5482/(A (.*)   (CE){0,6} (*THEN)  | A D) z/x
5483\= Expect no match
5484    AbcdCEBefgBhiBqz
5485
5486/(A (.*)   (CE*){0,6} (*THEN)  | A D) (*FAIL)/x
5487\= Expect no match
5488    AbcdCBefgBhiBqz
5489
5490/(A (.*)   (CE*){0,6} (*THEN)  | A D) z/x
5491\= Expect no match
5492    AbcdCBefgBhiBqz
5493
5494/(?=a(*COMMIT)b|ac)ac|ac/
5495\= Expect no match
5496    ac
5497
5498/(?=a(*COMMIT)b|(ac)) ac | (a)c/x
5499\= Expect no match
5500    ac
5501
5502# ----
5503
5504/(?(?!b(*THEN)a)bn|bnn)/
5505    bnn
5506
5507/(?!b(*SKIP)a)bn|bnn/
5508    bnn
5509
5510/(?(?!b(*SKIP)a)bn|bnn)/
5511    bnn
5512
5513/(?!b(*PRUNE)a)bn|bnn/
5514    bnn
5515
5516/(?(?!b(*PRUNE)a)bn|bnn)/
5517    bnn
5518
5519/(?!b(*COMMIT)a)bn|bnn/
5520    bnn
5521
5522/(?(?!b(*COMMIT)a)bn|bnn)/
5523   bnn
5524
5525/(?=b(*SKIP)a)bn|bnn/
5526\= Expect no match
5527    bnn
5528
5529/(?=b(*THEN)a)bn|bnn/
5530    bnn
5531
5532/^(?!a(*SKIP)b)/
5533    ac
5534
5535/^(?!a(*SKIP)b)../
5536    acd
5537
5538/(?!a(*SKIP)b)../
5539    acd
5540
5541/^(?(?!a(*SKIP)b))/
5542    ac
5543
5544/^(?!a(*PRUNE)b)../
5545    acd
5546
5547/(?!a(*PRUNE)b)../
5548    acd
5549
5550/(?!a(*COMMIT)b)ac|cd/
5551    ac
5552
5553/\A.*?(?:a|bc)/
5554    ba
5555
5556/^(A(*THEN)B|C(*THEN)D)/
5557    CD
5558
5559/(*:m(m)(?&y)(?(DEFINE)(?<y>b))/mark
5560    abc
5561
5562/(*PRUNE:m(m)(?&y)(?(DEFINE)(?<y>b))/mark
5563    abc
5564
5565/(*SKIP:m(m)(?&y)(?(DEFINE)(?<y>b))/mark
5566    abc
5567
5568/(*THEN:m(m)(?&y)(?(DEFINE)(?<y>b))/mark
5569    abc
5570
5571/^\d*\w{4}/
5572    1234
5573\= Expect no match
5574    123
5575
5576/^[^b]*\w{4}/
5577    aaaa
5578\= Expect no match
5579    aaa
5580
5581/^[^b]*\w{4}/i
5582    aaaa
5583\= Expect no match
5584    aaa
5585
5586/^a*\w{4}/
5587    aaaa
5588\= Expect no match
5589    aaa
5590
5591/^a*\w{4}/i
5592    aaaa
5593\= Expect no match
5594    aaa
5595
5596/(?:(?<n>foo)|(?<n>bar))\k<n>/dupnames
5597    foofoo
5598    barbar
5599
5600/(?<n>A)(?:(?<n>foo)|(?<n>bar))\k<n>/dupnames
5601    AfooA
5602    AbarA
5603\= Expect no match
5604    Afoofoo
5605    Abarbar
5606
5607/^(\d+)\s+IN\s+SOA\s+(\S+)\s+(\S+)\s*\(\s*$/
5608    1 IN SOA non-sp1 non-sp2(
5609
5610/^ (?:(?<A>A)|(?'B'B)(?<A>A)) (?('A')x) (?(<B>)y)$/x,dupnames
5611    Ax
5612    BAxy
5613
5614/^A\xZ/
5615    A\0Z
5616
5617/^A\o{123}B/
5618    A\123B
5619
5620/ ^ a + + b $ /x
5621    aaaab
5622
5623/ ^ a + #comment
5624  + b $ /x
5625    aaaab
5626
5627/ ^ a + #comment
5628  #comment
5629  + b $ /x
5630    aaaab
5631
5632/ ^ (?> a + ) b $ /x
5633    aaaab
5634
5635/ ^ ( a + ) + + \w $ /x
5636    aaaab
5637
5638/(?:a\Kb)*+/aftertext
5639    ababc
5640
5641/(?>a\Kb)*/aftertext
5642    ababc
5643
5644/(?:a\Kb)*/aftertext
5645    ababc
5646
5647/(a\Kb)*+/aftertext
5648    ababc
5649
5650/(a\Kb)*/aftertext
5651    ababc
5652
5653/(?:x|(?:(xx|yy)+|x|x|x|x|x)|a|a|a)bc/
5654\= Expect no match
5655    acb
5656
5657/\A(?:[^\"]++|\"(?:[^\"]*+|\"\")*+\")++/
5658    NON QUOTED \"QUOT\"\"ED\" AFTER \"NOT MATCHED
5659
5660/\A(?:[^\"]++|\"(?:[^\"]++|\"\")*+\")++/
5661    NON QUOTED \"QUOT\"\"ED\" AFTER \"NOT MATCHED
5662
5663/\A(?:[^\"]++|\"(?:[^\"]++|\"\")++\")++/
5664    NON QUOTED \"QUOT\"\"ED\" AFTER \"NOT MATCHED
5665
5666/\A([^\"1]++|[\"2]([^\"3]*+|[\"4][\"5])*+[\"6])++/
5667    NON QUOTED \"QUOT\"\"ED\" AFTER \"NOT MATCHED
5668
5669/^\w+(?>\s*)(?<=\w)/
5670    test test
5671
5672/(?P<same>a)(?P<same>b)/g,dupnames
5673    abbaba
5674
5675/(?P<same>a)(?P<same>b)(?P=same)/g,dupnames
5676    abbaba
5677
5678/(?P=same)?(?P<same>a)(?P<same>b)/g,dupnames
5679    abbaba
5680
5681/(?:(?P=same)?(?:(?P=same)(?P<same>a)(?P=same)|(?P=same)?(?P<same>b)(?P=same)){2}(?P=same)(?P<same>c)(?P=same)){2}(?P<same>z)?/g,dupnames
5682\= Expect no match
5683    bbbaaaccccaaabbbcc
5684
5685/(?P<Name>a)?(?P<Name2>b)?(?(<Name>)c|d)*l/
5686    acl
5687    bdl
5688    adl
5689    bcl
5690
5691/\sabc/
5692    \x{0b}abc
5693
5694/[\Qa]\E]+/
5695    aa]]
5696
5697/[\Q]a\E]+/
5698    aa]]
5699
5700/A((((((((a))))))))\8B/
5701    AaaB
5702
5703/A(((((((((a)))))))))\9B/
5704    AaaB
5705
5706/A[\8\9]B/
5707    A8B
5708    A9B
5709
5710/(|ab)*?d/
5711   abd
5712   xyd
5713
5714/(?:((abcd))|(((?:(?:(?:(?:abc|(?:abcdef))))b)abcdefghi)abc)|((*ACCEPT)))/
5715    1234abcd
5716
5717/(\2|a)(\1)/
5718    aaa
5719
5720/(\2)(\1)/
5721
5722/Z*(|d*){216}/
5723
5724/(?1)(?#?'){8}(a)/
5725    baaaaaaaaac
5726
5727/((((((((((((x))))))))))))\12/
5728    xx
5729
5730/A[\8]B[\9]C/
5731    A8B9C
5732
5733/(?1)()((((((\1++))\x85)+)|))/
5734    \x85\x85
5735
5736/(?|(\k'Pm')|(?'Pm'))/
5737    abcd
5738
5739/(?|(aaa)|(b))\g{1}/
5740    aaaaaa
5741    bb
5742
5743/(?|(aaa)|(b))(?1)/
5744    aaaaaa
5745    baaa
5746\= Expect no match
5747    bb
5748
5749/(?|(aaa)|(b))/
5750    xaaa
5751    xbc
5752
5753/(?|(?'a'aaa)|(?'a'b))\k'a'/
5754    aaaaaa
5755    bb
5756
5757/(?|(?'a'aaa)|(?'a'b))(?'a'cccc)\k'a'/dupnames
5758    aaaccccaaa
5759    bccccb
5760
5761# /x does not apply to MARK labels
5762
5763/x (*MARK:ab cd # comment
5764ef) x/x,mark
5765    axxz
5766
5767/(?<=a(B){0}c)X/
5768    acX
5769
5770/(?<DEFINE>b)(?(DEFINE)(a+))(?&DEFINE)/
5771    bbbb
5772\= Expect no match
5773    baaab
5774
5775/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[,;:])(?=.{8,16})(?!.*[\s])/
5776    \   Fred:099
5777
5778/(?=.*X)X$/
5779    \  X
5780
5781/(?s)(?=.*?)b/
5782    aabc
5783
5784/(Z)(a)\2{1,2}?(?-i)\1X/i
5785    ZaAAZX
5786
5787/(?'c')XX(?'YYYYYYYYYYYYYYYYYYYYYYYCl')/
5788
5789/[s[:digit:]\E-H]+/
5790    s09-H
5791
5792/[s[:digit:]\Q\E-H]+/
5793    s09-H
5794
5795/a+(?:|b)a/
5796    aaaa
5797
5798/X?(R||){3335}/
5799
5800/(?1)(A(*COMMIT)|B)D/
5801    ABD
5802    XABD
5803    BAD
5804    ABXABD
5805\= Expect no match
5806    ABX
5807
5808/(?(DEFINE)(?<m> 1? (?=(?<cond>2)?) 1 2 (?('cond')|3)))
5809    \A
5810    ()
5811    (?&m)
5812    \Z/x
5813    123
5814
5815/^(?:
5816(?: A| (1? (?=(?<cond>2)?) (1) 2 (?('cond')|3)) )
5817(Z)
5818)+$/x
5819    AZ123Z
5820\= Expect no match
5821    AZ12Z
5822
5823/^ (?(DEFINE) ( (?!(a)\2b)..) )   ()(?1)  /x
5824    acb
5825\= Expect no match
5826    aab
5827
5828/(?>ab|abab){1,5}?M/
5829    abababababababababababM
5830
5831/(?>ab|abab){2}?M/
5832    abababM
5833
5834/((?(?=(a))a)+k)/
5835    bbak
5836
5837/((?(?=(a))a|)+k)/
5838    bbak
5839
5840/(?(?!(b))a|b)+k/
5841    ababbalbbadabak
5842
5843/(?!(b))c|b/
5844    Ab
5845    Ac
5846
5847/(?=(b))b|c/
5848    Ab
5849    Ac
5850
5851/^(.|(.)(?1)\2)$/
5852    a
5853    aba
5854    abcba
5855    ababa
5856    abcdcba
5857
5858/^((.)(?1)\2|.?)$/
5859    a
5860    aba
5861    abba
5862    abcba
5863    ababa
5864    abccba
5865    abcdcba
5866    abcddcba
5867
5868/^(.)(\1|a(?2))/
5869    bab
5870
5871/^(.|(.)(?1)?\2)$/
5872    abcba
5873
5874/^(?(?=(a))abc|def)/
5875    abc
5876
5877/^(?(?!(a))def|abc)/
5878    abc
5879
5880/^(?(?=(a)(*ACCEPT))abc|def)/
5881    abc
5882
5883/^(?(?!(a)(*ACCEPT))def|abc)/
5884    abc
5885
5886/^(?1)\d{3}(a)/
5887    a123a
5888
5889# This pattern uses a lot of named subpatterns in order to match email
5890# addresses in various formats. It's a heavy test for named subpatterns. In the
5891# <atext> group, slash is coded as \x{2f} so that this pattern can also be
5892# processed by perltest.sh, which does not cater for an escaped delimiter
5893# within the pattern. $ within the pattern must also be escaped. All $ and @
5894# characters in subject strings are escaped so that Perl doesn't interpret them
5895# as variable insertions and " characters must also be escaped for Perl.
5896
5897# This set of subpatterns is more or less a direct transliteration of the BNF
5898# definitions in RFC2822, without any of the obsolete features. The addition of
5899# a possessive + to the definition of <phrase> reduced the match limit in PCRE2
5900# from over 5 million to just under 400, and eliminated a very noticeable delay
5901# when this file was passed to perltest.sh.
5902
5903/(?ix)(?(DEFINE)
5904(?<addr_spec>       (?&local_part) \@ (?&domain) )
5905(?<angle_addr>      (?&CFWS)?+ < (?&addr_spec) > (?&CFWS)?+ )
5906(?<atext>           [a-z\d!#\$%&'*+-\x{2f}=?^_`{|}~] )
5907(?<atom>            (?&CFWS)?+ (?&atext)+ (?&CFWS)?+ )
5908(?<ccontent>        (?&ctext) | (?&quoted_pair) | (?&comment) )
5909(?<ctext>           [^\x{9}\x{10}\x{13}\x{7f}-\x{ff}\ ()\\] )
5910(?<comment>         \( (?: (?&FWS)?+ (?&ccontent) )*+ (?&FWS)?+ \) )
5911(?<CFWS>            (?: (?&FWS)?+ (?&comment) )* (?# NOT possessive)
5912                    (?: (?&FWS)?+ (?&comment) | (?&FWS) ) )
5913(?<dcontent>        (?&dtext) | (?&quoted_pair) )
5914(?<display_name>    (?&phrase) )
5915(?<domain>          (?&dot_atom) | (?&domain_literal) )
5916(?<domain_literal>  (?&CFWS)?+ \[ (?: (?&FWS)?+ (?&dcontent) )* (?&FWS)?+ \]
5917                    (?&CFWS)?+ )
5918(?<dot_atom>        (?&CFWS)?+ (?&dot_atom_text) (?&CFWS)?+ )
5919(?<dot_atom_text>   (?&atext)++ (?: \. (?&atext)++)*+ )
5920(?<dtext>           [^\x{9}\x{10}\x{13}\x{7f}-\x{ff}\ \[\]\\] )
5921(?<FWS>             (?: [\t\ ]*+ \n)?+ [\t\ ]++ )
5922(?<local_part>      (?&dot_atom) | (?&quoted_string)  )
5923(?<mailbox>         (?&name_addr) | (?&addr_spec) )
5924(?<name_addr>       (?&display_name)? (?&angle_addr) )
5925(?<phrase>          (?&word)++ )
5926(?<qcontent>        (?&qtext) | (?&quoted_pair) )
5927(?<quoted_pair>     " (?&text) )
5928(?<quoted_string>   (?&CFWS)?+ " (?: (?&FWS)?+ (?&qcontent))* (?&FWS)?+ "
5929                    (?&CFWS)?+ )
5930(?<qtext>           [^\x{9}\x{10}\x{13}\x{7f}-\x{ff}\ "\\] )
5931(?<text>            [^\r\n] )
5932(?<word>            (?&atom) | (?&quoted_string) )
5933) # End DEFINE
5934^(?&mailbox)$/
5935    Alan Other <user\@dom.ain>
5936    <user\@dom.ain>
5937    user\@dom.ain
5938    user\@[]
5939    user\@[domain literal]
5940    user\@[domain literal with \"[square brackets\"] inside]
5941    \"A. Other\" <user.1234\@dom.ain> (a comment)
5942    A. Other <user.1234\@dom.ain> (a comment)
5943    \"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"\@x400-re.lay
5944\= Expect no match
5945    A missing angle <user\@some.where
5946    The quick brown fox
5947
5948# --------------------------------------------------------------------------
5949
5950# This pattern uses named groups to match default PCRE2 patterns. It's another
5951# heavy test for named subpatterns. Once again, code slash as \x{2f} and escape
5952# $ even in classes so that this works with pcre2test.
5953
5954/(?sx)(?(DEFINE)
5955
5956(?<assertion>         (?&simple_assertion) | (?&lookaround) )
5957
5958(?<atomic_group>      \( \? > (?&regex) \) )
5959
5960(?<back_reference>    \\ \d+ |
5961                      \\g (?: [+-]?\d+ | \{ (?: [+-]?\d+ | (?&groupname) ) \} ) |
5962                      \\k <(?&groupname)> |
5963                      \\k '(?&groupname)' |
5964                      \\k \{ (?&groupname) \} |
5965                      \( \? P= (?&groupname) \) )
5966
5967(?<branch>            (?:(?&assertion) |
5968                         (?&callout) |
5969                         (?&comment) |
5970                         (?&option_setting) |
5971                         (?&qualified_item) |
5972                         (?&quoted_string) |
5973                         (?&quoted_string_empty) |
5974                         (?&special_escape) |
5975                         (?&verb)
5976                      )* )
5977
5978(?<callout>           \(\?C (?: \d+ |
5979                      (?: (?<D>["'`^%\#\$])
5980                        (?: \k'D'\k'D' | (?!\k'D') . )* \k'D' |
5981                      \{ (?: \}\} | [^}]*+ )* \} )
5982                      )? \) )
5983
5984(?<capturing_group>   \( (?: \? P? < (?&groupname) > | \? ' (?&groupname) ' )?
5985                      (?&regex) \) )
5986
5987(?<character_class>   \[ \^?+ (?: \] (?&class_item)* | (?&class_item)+ ) \] )
5988
5989(?<character_type>    (?! \\N\{\w+\} ) \\ [dDsSwWhHvVRN] )
5990
5991(?<class_item>        (?: \[ : (?:
5992                      alnum|alpha|ascii|blank|cntrl|digit|graph|lower|print|
5993                      punct|space|upper|word|xdigit
5994                      ) : \] |
5995                      (?&quoted_string) |
5996                      (?&quoted_string_empty) |
5997                      (?&escaped_character) |
5998                      (?&character_type) |
5999                      [^]] ) )
6000
6001(?<comment>           \(\?\# [^)]* \) | (?&quoted_string_empty) | \\E )
6002
6003(?<condition>         (?: \( [+-]? \d+ \) |
6004                          \( < (?&groupname) > \) |
6005                          \( ' (?&groupname) ' \) |
6006                          \( R \d* \) |
6007                          \( R & (?&groupname) \) |
6008                          \( (?&groupname) \) |
6009                          \( DEFINE \) |
6010                          \( VERSION >?=\d+(?:\.\d\d?)? \) |
6011                          (?&callout)?+ (?&comment)* (?&lookaround) ) )
6012
6013(?<conditional_group> \(\? (?&condition) (?&branch) (?: \| (?&branch) )? \) )
6014
6015(?<delimited_regex>   (?<delimiter> [-\x{2f}!"'`=_:;,%&@~]) (?&regex)
6016                      \k'delimiter' .* )
6017
6018(?<escaped_character> \\ (?: 0[0-7]{1,2} | [0-7]{1,3} | o\{ [0-7]+ \} |
6019                      x \{ (*COMMIT) [[:xdigit:]]* \} | x [[:xdigit:]]{0,2} |
6020                      [aefnrt] | c[[:print:]] |
6021                      [^[:alnum:]] ) )
6022
6023(?<group>             (?&capturing_group) | (?&non_capturing_group) |
6024                      (?&resetting_group) | (?&atomic_group) |
6025                      (?&conditional_group) )
6026
6027(?<groupname>         [a-zA-Z_]\w* )
6028
6029(?<literal_character> (?! (?&range_qualifier) ) [^[()|*+?.\$\\] )
6030
6031(?<lookaround>        \(\? (?: = | ! | <= | <! ) (?&regex) \) )
6032
6033(?<non_capturing_group> \(\? [iJmnsUx-]* : (?&regex) \) )
6034
6035(?<option_setting>    \(\? [iJmnsUx-]* \) )
6036
6037(?<qualified_item>    (?:\. |
6038                         (?&lookaround) |
6039                         (?&back_reference) |
6040                         (?&character_class) |
6041                         (?&character_type) |
6042                         (?&escaped_character) |
6043                         (?&group) |
6044                         (?&subroutine_call) |
6045                         (?&literal_character) |
6046                         (?&quoted_string)
6047                      ) (?&comment)? (?&qualifier)? )
6048
6049(?<qualifier>         (?: [?*+] | (?&range_qualifier) ) [+?]? )
6050
6051(?<quoted_string>     (?: \\Q (?: (?!\\E | \k'delimiter') . )++ (?: \\E | ) ) )
6052
6053(?<quoted_string_empty>  \\Q\\E )
6054
6055(?<range_qualifier>   \{ (?: \d+ (?: , \d* )? | , \d+ ) \} )
6056
6057(?<regex>             (?&start_item)* (?&branch) (?: \| (?&branch) )* )
6058
6059(?<resetting_group>   \( \? \| (?&regex) \) )
6060
6061(?<simple_assertion>  \^ | \$ | \\A | \\b | \\B | \\G | \\z | \\Z )
6062
6063(?<special_escape>    \\K )
6064
6065(?<start_item>        \( \* (?:
6066                      ANY |
6067                      ANYCRLF |
6068                      BSR_ANYCRLF |
6069                      BSR_UNICODE |
6070                      CR |
6071                      CRLF |
6072                      LF |
6073                      LIMIT_MATCH=\d+ |
6074                      LIMIT_DEPTH=\d+ |
6075                      LIMIT_HEAP=\d+ |
6076                      NOTEMPTY |
6077                      NOTEMPTY_ATSTART |
6078                      NO_AUTO_POSSESS |
6079                      NO_DOTSTAR_ANCHOR |
6080                      NO_JIT |
6081                      NO_START_OPT |
6082                      NUL |
6083                      UTF |
6084                      UCP ) \) )
6085
6086(?<subroutine_call>   (?: \(\?R\) | \(\?[+-]?\d+\) |
6087                      \(\? (?: & | P> ) (?&groupname) \) |
6088                      \\g < (?&groupname) > |
6089                      \\g ' (?&groupname) ' |
6090                      \\g < [+-]? \d+ > |
6091                      \\g ' [+-]? \d+ ) )
6092
6093(?<verb>              \(\* (?: ACCEPT | FAIL | F | COMMIT |
6094                      (?:MARK)?:(?&verbname) |
6095                      (?:PRUNE|SKIP|THEN) (?: : (?&verbname)? )? ) \) )
6096
6097(?<verbname>          [^)]+ )
6098
6099) # End DEFINE
6100# Kick it all off...
6101^(?&delimited_regex)$/subject_literal,jitstack=256
6102    /^(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\11*(\3\4)\1(?#)2$/
6103    /(cat(a(ract|tonic)|erpillar)) \1()2(3)/
6104    /^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/
6105    /^From\s+\S+\s+([a-zA-Z]{3}\s+){2}\d{1,2}\s+\d\d:\d\d/
6106    /<tr([\w\W\s\d][^<>]{0,})><TD([\w\W\s\d][^<>]{0,})>([\d]{0,}\.)(.*)((<BR>([\w\W\s\d][^<>]{0,})|[\s]{0,}))<\/a><\/TD><TD([\w\W\s\d][^<>]{0,})>([\w\W\s\d][^<>]{0,})<\/TD><TD([\w\W\s\d][^<>]{0,})>([\w\W\s\d][^<>]{0,})<\/TD><\/TR>/is
6107    /^(?(DEFINE) (?<A> a) (?<B> b) )  (?&A) (?&B) /
6108    /(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
6109    /\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
6110    /^(\w++|\s++)*$/
6111    /a+b?(*THEN)c+(*FAIL)/
6112    /(A (A|B(*ACCEPT)|C) D)(E)/x
6113    /^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$/i
6114    /A(*PRUNE)B(*SKIP)C(*THEN)D(*COMMIT)E(*F)F(*FAIL)G(?!)H(*ACCEPT)I/B
6115    /(?C`a``b`)(?C'a''b')(?C"a""b")(?C^a^^b^)(?C%a%%b%)(?C#a##b#)(?C$a$$b$)(?C{a}}b})/B,callout_info
6116    /(?sx)(?(DEFINE)(?<assertion> (?&simple_assertion) | (?&lookaround) )(?<atomic_group> \( \? > (?&regex) \) )(?<back_reference> \\ \d+ | \\g (?: [+-]?\d+ | \{ (?: [+-]?\d+ | (?&groupname) ) \} ) | \\k <(?&groupname)> | \\k '(?&groupname)' | \\k \{ (?&groupname) \} | \( \? P= (?&groupname) \) )(?<branch> (?:(?&assertion) | (?&callout) | (?&comment) | (?&option_setting) | (?&qualified_item) | (?&quoted_string) | (?&quoted_string_empty) | (?&special_escape) | (?&verb) )* )(?<callout> \(\?C (?: \d+ | (?: (?<D>["'`^%\#\$]) (?: \k'D'\k'D' | (?!\k'D') . )* \k'D' | \{ (?: \}\} | [^}]*+ )* \} ) )? \) )(?<capturing_group> \( (?: \? P? < (?&groupname) > | \? ' (?&groupname) ' )? (?&regex) \) )(?<character_class> \[ \^?+ (?: \] (?&class_item)* | (?&class_item)+ ) \] )(?<character_type> (?! \\N\{\w+\} ) \\ [dDsSwWhHvVRN] )(?<class_item> (?: \[ : (?: alnum|alpha|ascii|blank|cntrl|digit|graph|lower|print| punct|space|upper|word|xdigit ) : \] | (?&quoted_string) | (?&quoted_string_empty) | (?&escaped_character) | (?&character_type) | [^]] ) )(?<comment> \(\?\# [^)]* \) | (?&quoted_string_empty) | \\E )(?<condition> (?: \( [+-]? \d+ \) | \( < (?&groupname) > \) | \( ' (?&groupname) ' \) | \( R \d* \) | \( R & (?&groupname) \) | \( (?&groupname) \) | \( DEFINE \) | \( VERSION >?=\d+(?:\.\d\d?)? \) | (?&callout)?+ (?&comment)* (?&lookaround) ) )(?<conditional_group> \(\? (?&condition) (?&branch) (?: \| (?&branch) )? \) )(?<delimited_regex> (?<delimiter> [-\x{2f}!"'`=_:;,%&@~]) (?&regex) \k'delimiter' .* )(?<escaped_character> \\ (?: 0[0-7]{1,2} | [0-7]{1,3} | o\{ [0-7]+ \} | x \{ (*COMMIT) [[:xdigit:]]* \} | x [[:xdigit:]]{0,2} | [aefnrt] | c[[:print:]] | [^[:alnum:]] ) )(?<group> (?&capturing_group) | (?&non_capturing_group) | (?&resetting_group) | (?&atomic_group) | (?&conditional_group) )(?<groupname> [a-zA-Z_]\w* )(?<literal_character> (?! (?&range_qualifier) ) [^[()|*+?.\$\\] )(?<lookaround> \(\? (?: = | ! | <= | <! ) (?&regex) \) )(?<non_capturing_group> \(\? [iJmnsUx-]* : (?&regex) \) )(?<option_setting> \(\? [iJmnsUx-]* \) )(?<qualified_item> (?:\. | (?&lookaround) | (?&back_reference) | (?&character_class) | (?&character_type) | (?&escaped_character) | (?&group) | (?&subroutine_call) | (?&literal_character) | (?&quoted_string) ) (?&comment)? (?&qualifier)? )(?<qualifier> (?: [?*+] | (?&range_qualifier) ) [+?]? )(?<quoted_string> (?: \\Q (?: (?!\\E | \k'delimiter') . )++ (?: \\E | ) ) ) (?<quoted_string_empty> \\Q\\E ) (?<range_qualifier> \{ (?: \d+ (?: , \d* )? | , \d+ ) \} )(?<regex> (?&start_item)* (?&branch) (?: \| (?&branch) )* )(?<resetting_group> \( \? \| (?&regex) \) )(?<simple_assertion> \^ | \$ | \\A | \\b | \\B | \\G | \\z | \\Z )(?<special_escape> \\K )(?<start_item> \( \* (?: ANY | ANYCRLF | BSR_ANYCRLF | BSR_UNICODE | CR | CRLF | LF | LIMIT_MATCH=\d+ | LIMIT_DEPTH=\d+ | LIMIT_HEAP=\d+ | NOTEMPTY | NOTEMPTY_ATSTART | NO_AUTO_POSSESS | NO_DOTSTAR_ANCHOR | NO_JIT | NO_START_OPT | NUL | UTF | UCP ) \) )(?<subroutine_call> (?: \(\?R\) | \(\?[+-]?\d+\) | \(\? (?: & | P> ) (?&groupname) \) | \\g < (?&groupname) > | \\g ' (?&groupname) ' | \\g < [+-]? \d+ > | \\g ' [+-]? \d+ ) )(?<verb> \(\* (?: ACCEPT | FAIL | F | COMMIT | (?:MARK)?:(?&verbname) | (?:PRUNE|SKIP|THEN) (?: : (?&verbname)? )? ) \) )(?<verbname> [^)]+ ))^(?&delimited_regex)$/
6117\= Expect no match
6118    /((?(?C'')\QX\E(?!((?(?C'')(?!X=X));=)r*X=X));=)/
6119    /(?:(?(2y)a|b)(X))+/
6120    /a(*MARK)b/
6121    /a(*CR)b/
6122    /(?P<abn>(?P=abn)(?<badstufxxx)/
6123
6124# --------------------------------------------------------------------------
6125
6126/<(?x:[a b])>/xx
6127    < >
6128
6129/<(?:[a b])>/xx
6130    < >
6131
6132/<(?xxx:[a b])>/
6133    < >
6134
6135/<(?-x:[a b])>/xx
6136    < >
6137
6138/[[:digit:]-]+/
6139    12-24
6140
6141/((?<=((*ACCEPT)) )\1?\b) /
6142\= Expect no match
6143    ((?<=((*ACCEPT)) )\\1?\\b)\x20
6144
6145/((?<=((*ACCEPT))X)\1?Y)\1/
6146    XYYZ
6147
6148/((?<=((*ACCEPT))X)\1?Y(*ACCEPT))\1/
6149    XYYZ
6150
6151/(?(DEFINE)(?<optional_a>a?)X)^(?&optional_a)a$/
6152    aa
6153    a
6154
6155/^(a?)b(?1)a/
6156    abaa
6157    aba
6158    baa
6159    ba
6160
6161/^(a?)+b(?1)a/
6162    abaa
6163    aba
6164    baa
6165    ba
6166
6167/^(a?)++b(?1)a/
6168    abaa
6169    aba
6170    baa
6171    ba
6172
6173/^(a?)+b/
6174    b
6175    ab
6176    aaab
6177
6178/(?=a+)a(a+)++b/
6179    aab
6180
6181/(?<=\G.)/g,aftertext
6182    abc
6183
6184/(?<=(?=.)?)/
6185
6186/(?<=(?=.)?+)/
6187
6188/(?<=(?=.)*)/
6189
6190/(?<=(?=.){4,5})/
6191
6192/(?<=(?=.){4,5}x)/
6193
6194/a(?=.(*:X))(*SKIP:X)(*F)|(.)/
6195    abc
6196
6197/a(?>(*:X))(*SKIP:X)(*F)|(.)/
6198    abc
6199
6200/a(?:(*:X))(*SKIP:X)(*F)|(.)/
6201    abc
6202
6203#pattern no_start_optimize
6204
6205/(?>a(*:1))(?>b(*:1))(*SKIP:1)x|.*/
6206    abc
6207
6208/(?>a(*:1))(?>b)(*SKIP:1)x|.*/
6209    abc
6210
6211#subject mark
6212
6213/a(*ACCEPT:X)b/
6214    abc
6215
6216/(?=a(*ACCEPT:QQ)bc)axyz/
6217    axyz
6218
6219/(?(DEFINE)(a(*ACCEPT:X)))(?1)b/
6220    abc
6221
6222/a(*F:X)b/
6223    abc
6224
6225/(?(DEFINE)(a(*F:X)))(?1)b/
6226    abc
6227
6228/a(*COMMIT:X)b/
6229    abc
6230
6231/(?(DEFINE)(a(*COMMIT:X)))(?1)b/
6232    abc
6233
6234/a+(*:Z)b(*COMMIT:X)(*SKIP:Z)c|.*/
6235    aaaabd
6236
6237/a+(*:Z)b(*COMMIT:X)(*SKIP:X)c|.*/
6238    aaaabd
6239
6240/a(*COMMIT:X)b/
6241    axabc
6242
6243#pattern -no_start_optimize
6244#subject -mark
6245
6246/(.COMMIT)(*COMMIT::::::::::interal error:::)/
6247
6248/(*COMMIT:��)/
6249
6250/(*COMMIT:]w)/
6251
6252/(?i)A(?^)B(?^x:C D)(?^i)e f/
6253    aBCDE F
6254\= Expect no match
6255    aBCDEF
6256    AbCDe f
6257
6258/(*pla:foo).{6}/
6259    abcfoobarxyz
6260\= Expect no match
6261    abcfooba
6262
6263/(*positive_lookahead:foo).{6}/
6264    abcfoobarxyz
6265
6266/(?(*pla:foo).{6}|a..)/
6267    foobarbaz
6268    abcfoobar
6269
6270/(?(*positive_lookahead:foo).{6}|a..)/
6271    foobarbaz
6272    abcfoobar
6273
6274/(*plb:foo)bar/
6275    abcfoobar
6276\= Expect no match
6277    abcbarfoo
6278
6279/(*positive_lookbehind:foo)bar/
6280    abcfoobar
6281\= Expect no match
6282    abcbarfoo
6283
6284/(?(*plb:foo)bar|baz)/
6285    abcfoobar
6286    bazfoobar
6287    abcbazfoobar
6288    foobazfoobar
6289
6290/(?(*positive_lookbehind:foo)bar|baz)/
6291    abcfoobar
6292    bazfoobar
6293    abcbazfoobar
6294    foobazfoobar
6295
6296/(*nlb:foo)bar/
6297    abcbarfoo
6298\= Expect no match
6299    abcfoobar
6300
6301/(*negative_lookbehind:foo)bar/
6302    abcbarfoo
6303\= Expect no match
6304    abcfoobar
6305
6306/(?(*nlb:foo)bar|baz)/
6307    abcfoobaz
6308    abcbarbaz
6309\= Expect no match
6310    abcfoobar
6311
6312/(?(*negative_lookbehind:foo)bar|baz)/
6313    abcfoobaz
6314    abcbarbaz
6315\= Expect no match
6316    abcfoobar
6317
6318/(*atomic:a+)\w/
6319    aaab
6320\= Expect no match
6321    aaaa
6322
6323/   (?<word> \w+ )*    \.   /xi
6324    pokus.
6325
6326/(?(DEFINE) (?<word> \w+ ) ) (?&word)*   \./xi
6327    pokus.
6328
6329/(?(DEFINE) (?<word> \w+ ) ) ( (?&word)* )   \./xi
6330    pokus.
6331
6332/(?&word)*  (?(DEFINE) (?<word> \w+ ) )  \./xi
6333    pokus.
6334
6335/(?&word)*  \. (?<word> \w+ )/xi
6336    pokus.hokus
6337
6338/a(?(?=(*:2)b).)/mark
6339    abc
6340    acb
6341
6342/a(?(?!(*:2)b).)/mark
6343    acb
6344    abc
6345
6346/(?:a|ab){1}+c/
6347\= Expect no match
6348    abc
6349
6350/(a|ab){1}+c/
6351    abc
6352
6353/(a+){1}+a/
6354\= Expect no match
6355    aaaa
6356
6357/(?(DEFINE)(a|ab))(?1){1}+c/
6358    abc
6359
6360/(?:a|(?=b)|.)*\z/
6361    abc
6362
6363/(?:a|(?=b)|.)*/
6364    abc
6365
6366/(?<=a(*SKIP)x)|c/
6367    abcd
6368
6369/(?<=a(*SKIP)x)|d/
6370    abcd
6371
6372/(?<=(?=.(?<=x)))/aftertext
6373    abx
6374
6375/(?<=(?=(?<=a)))b/
6376    ab
6377
6378/^(?<A>a)(?(<A>)b)((?<=b).*)$/
6379    abc
6380
6381/^(a\1?){4}$/
6382    aaaa
6383    aaaaaa
6384
6385/^((\1+)|\d)+133X$/
6386    111133X
6387
6388/^(?>.*?([A-Z])(?!.*\1)){26}/i
6389    The quick brown fox jumps over the lazy dog.
6390    Jackdaws love my big sphinx of quartz.
6391    Pack my box with five dozen liquor jugs.
6392\= Expect no match
6393    The quick brown fox jumps over the lazy cat.
6394    Hackdaws love my big sphinx of quartz.
6395    Pack my fox with five dozen liquor jugs.
6396
6397/(?<=X(?(DEFINE)(A)))X(*F)/
6398\= Expect no match
6399    AXYZ
6400
6401/(?<=X(?(DEFINE)(A)))./
6402    AXYZ
6403
6404/(?<=X(?(DEFINE)(.*))Y)./
6405    AXYZ
6406
6407/(?<=X(?(DEFINE)(Y))(?1))./
6408    AXYZ
6409
6410/(?(DEFINE)(?<foo>bar))(?<![-a-z0-9])word/
6411    word
6412
6413/a{1,2,3}b/
6414    a{1,2,3}b
6415
6416/\214748364/
6417    >\x{8c}748364<
6418
6419/a{65536/
6420    >a{65536<
6421
6422/a\K.(?0)*/
6423    abac
6424
6425/(a\K.(?1)*)/
6426    abac
6427
6428# --------------------------------------------------------------------------
6429# Perl-compatible tests of variable-length lookbehinds.
6430
6431/(?<=ab?c).../g
6432    abcdefgacxyz
6433
6434/(?<=PQR|ab?c).../g
6435    abcdefgacxyzPQR123
6436
6437/(?<=ab?c|PQR).../g
6438    abcdefgacxyzPQR123
6439
6440/(?<=PQ|ab?c).../g
6441    abcdefgacxyzPQR123
6442
6443/(?<=ab?c|PQ).../g
6444    abcdefgacxyzPQR123
6445
6446/(?<=a(b?c|d?e?e)f)X./g
6447     acfX1zzzaefX2zzzadeefX3zzzX4zzz
6448
6449/(?<!a(b?c|d?e?e)f)X./g
6450     acfX1zzzaefX2zzzadeefX3zzzX4zzz
6451
6452/(?(?<=ab?c)d|e)/
6453    abcdefg
6454    acdefg
6455    axdefg
6456
6457/(?<=\d{2,3}|ABC)./
6458    ABCD
6459
6460/(?<=(\d{1,255}))X/
6461    1234X
6462
6463/(?<=a(b?c){3}d)X/
6464   ZXacbccdXYZ
6465
6466/(?<=a(b?c){0}d)X/
6467   ZXadXYZ
6468
6469/(?<=a?(b?c){0}d)X./
6470   ZXadXYZ
6471
6472/(?<=\R)X/
6473    \x{0a}X
6474    a\x{0a}X
6475    a\x{0d}\x{0a}X
6476
6477# --------------------------------------------------------------------------
6478
6479# Altered interpretation of {,n}
6480
6481/a{,3}B/
6482    XBBB
6483    XaBBB
6484    XaaBBB
6485    XaaaBBB
6486    XaaaaBBB
6487
6488# But {,} remains not a qualifier
6489
6490/a{,}B/
6491    Xa{,}BBB
6492\= Expect no match
6493    XBBB
6494    XaBBB
6495
6496# Checks for non-quantifiers after refactored code
6497
6498/X{/
6499    ZZX{}YY
6500
6501/X{A/
6502    ZZX{ABC}
6503
6504/X{}/
6505    ZZX{}YZ
6506
6507/X{1234/
6508    ZZX{123456
6509
6510/X{12ABC}/
6511    ZZX{12ABC}Y
6512
6513/X{1,/
6514    ZZX{1,...
6515
6516/X{,9/
6517    ZZX{,9}abc
6518
6519/X{,9]/
6520    ZZX{,9]..
6521
6522# --------------------------------------------------------------------------
6523
6524/(A)(?-1)(?+1)(B)/
6525    xxAABBzz
6526
6527/(A)(\g{ -2 }B)/
6528    XAABX
6529
6530/(A)((?-2)B)/
6531    XAABX
6532
6533/a\c\X/
6534    --a\x1cX--
6535
6536/(a)\g{ 1 }/
6537    baab
6538
6539/a{ 1,2 }/
6540    Xaaaaa
6541
6542/a{ 1 , 2 }/
6543    Xaaaaa
6544
6545/(?'name'ab)\k{ name }(?P=name)/
6546    XabababX
6547
6548/A{,}B/
6549    A{,}B
6550
6551/A{ , }B/
6552    A{ , }B
6553
6554/A{ ,3}/
6555    AAAAAACC
6556
6557/A{ 3, }/
6558    BBAAAAAACC
6559
6560# This pattern validates regular expression patterns. The original that I was
6561# sent was this:
6562# /^((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)$/
6563# This is not very readable, and also does not handle all features. I have done
6564# some work on it.
6565
6566/^
6567(?<re>
6568# A regular expression is zero or more of these items.
6569  (?:
6570  # An item is one of these:
6571    (?:
6572      [^?+*{}()\[\]\\|]++|  # Non-meta characters or unquoted .
6573      \\.|                  # Quoted .
6574
6575      \[                    # Class, which is [
6576      (?:                   # Followed by
6577        \^?\\.|             # Optional ^ and any escaped character
6578        \^[^\\]|            # OR ^ and not escaped character
6579        [^\\^]              # OR neither ^ nor \
6580      )                     # Followed by
6581      (?:[^\]\\]+|\\.)*+    # Zero or more (not ] or \) OR escaped dot
6582      \]|                   # Class ends with ]
6583
6584      \(                    # Parenthesized group
6585        (?:                 # Start with optional
6586          \?[:=!]|          # ? followed by : = !
6587          \?<[=!]|          # OR ?< followed by = or !
6588          \?>               # OR ?>
6589        )?
6590        (?&re)??            # Then a nested <re>
6591      \)|                   # End parenthesized group
6592
6593      \(\?                  # Other parenthesized items
6594        (?:                 # (? followed by
6595          R|                # R
6596          [+-]?\d++         # Or optional +- and digits
6597        )
6598      \)|                   # End parens
6599
6600      \(\*                  # Verbs
6601        (?:
6602          COMMIT|
6603          FAIL|
6604          MARK:[^)]*|
6605          (?:PRUNE|SKIP|THEN)(?::[^\)]*+)?
6606        )
6607      \)
6608    )                       # End list of items
6609
6610    # Followed by an optional quantifier
6611
6612    (?:
6613      (?:
6614        [?+*]     # ?+*
6615        |         # OR
6616        \{\d+     # { digits
6617        (?:,\d*)? # optionally followed by ,digits
6618        \}        # then closing }
6619        |         # OR
6620        \{,\d+}   # {,digits}
6621      )
6622      [?+]?       # optional ungreedy or possessive
6623    )?
6624
6625    | # OR an "item" is a branch ending
6626
6627    \|
6628
6629  )*  # Zero or more top-level items.
6630)     # End regex group.
6631$/x
6632    [abcdef]
6633    [abc\\]def]
6634    a.b|abcd
6635    ab()d
6636    ab{1,3}d
6637    ab{,3}d
6638    ab(*FAIL)d(*COMMIT)(*SKIP)(*THEN:abc)
6639    ab(*MARK:xyz)
6640    (?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[,;:])(?=.{8,16})(?!.*[\\s])
6641    abcd\\t\\n\\r\\f\\a\\e\\071\\x3b\\^\\\\\\?caxyz
6642    a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz
6643    \\G(?:(?=(\\1.|)(.))){1,13}?(?!.*\\2.*\\2)\\1\\K\\2
6644\= Expect no match
6645    ab)d
6646    ab(d
6647    {4,5}
6648    a[]b
6649    (a)(?(1)a|b|c)
6650
6651/^..A(*SKIP)B|C/
6652    12ADC
6653
6654/(?<!a?)/
6655    a
6656
6657# End of testinput1
6658