1 /-- These tests are for the Perl >= 5.10 features that PCRE supports. --/ 2 3 /\H\h\V\v/ 4 X X\x0a 5 0: X X\x0a 6 X\x09X\x0b 7 0: X\x09X\x0b 8 ** Failers 9 No match 10 \xa0 X\x0a 11 No match 12 13 /\H*\h+\V?\v{3,4}/ 14 \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a 15 0: \x09 \xa0X\x0a\x0b\x0c\x0d 16 \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a 17 0: \x09 \xa0\x0a\x0b\x0c\x0d 18 \x09\x20\xa0\x0a\x0b\x0c 19 0: \x09 \xa0\x0a\x0b\x0c 20 ** Failers 21 No match 22 \x09\x20\xa0\x0a\x0b 23 No match 24 25 /\H{3,4}/ 26 XY ABCDE 27 0: ABCD 28 XY PQR ST 29 0: PQR 30 31 /.\h{3,4}./ 32 XY AB PQRS 33 0: B P 34 35 /\h*X\h?\H+Y\H?Z/ 36 >XNNNYZ 37 0: XNNNYZ 38 > X NYQZ 39 0: X NYQZ 40 ** Failers 41 No match 42 >XYZ 43 No match 44 > X NY Z 45 No match 46 47 /\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/ 48 >XY\x0aZ\x0aA\x0bNN\x0c 49 0: XY\x0aZ\x0aA\x0bNN\x0c 50 >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c 51 0: \x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c 52 53 /(foo)\Kbar/ 54 foobar 55 0: bar 56 1: foo 57 58 /(foo)(\Kbar|baz)/ 59 foobar 60 0: bar 61 1: foo 62 2: bar 63 foobaz 64 0: foobaz 65 1: foo 66 2: baz 67 68 /(foo\Kbar)baz/ 69 foobarbaz 70 0: barbaz 71 1: foobar 72 73 /abc\K|def\K/g+ 74 Xabcdefghi 75 0: 76 0+ defghi 77 0: 78 0+ ghi 79 80 /ab\Kc|de\Kf/g+ 81 Xabcdefghi 82 0: c 83 0+ defghi 84 0: f 85 0+ ghi 86 87 /(?=C)/g+ 88 ABCDECBA 89 0: 90 0+ CDECBA 91 0: 92 0+ CBA 93 94 /^abc\K/+ 95 abcdef 96 0: 97 0+ def 98 ** Failers 99 No match 100 defabcxyz 101 No match 102 103 /^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-02}Z/ 104 ababababbbabZXXXX 105 0: ababababbbabZ 106 1: ab 107 2: b 108 109 /(?<A>tom|bon)-\g{A}/ 110 tom-tom 111 0: tom-tom 112 1: tom 113 bon-bon 114 0: bon-bon 115 1: bon 116 117 /(^(a|b\g{-1}))/ 118 bacxxx 119 No match 120 121 /(?|(abc)|(xyz))\1/ 122 abcabc 123 0: abcabc 124 1: abc 125 xyzxyz 126 0: xyzxyz 127 1: xyz 128 ** Failers 129 No match 130 abcxyz 131 No match 132 xyzabc 133 No match 134 135 /(?|(abc)|(xyz))(?1)/ 136 abcabc 137 0: abcabc 138 1: abc 139 xyzabc 140 0: xyzabc 141 1: xyz 142 ** Failers 143 No match 144 xyzxyz 145 No match 146 147 /^X(?5)(a)(?|(b)|(q))(c)(d)(Y)/ 148 XYabcdY 149 0: XYabcdY 150 1: a 151 2: b 152 3: c 153 4: d 154 5: Y 155 156 /^X(?7)(a)(?|(b|(r)(s))|(q))(c)(d)(Y)/ 157 XYabcdY 158 0: XYabcdY 159 1: a 160 2: b 161 3: <unset> 162 4: <unset> 163 5: c 164 6: d 165 7: Y 166 167 /^X(?7)(a)(?|(b|(?|(r)|(t))(s))|(q))(c)(d)(Y)/ 168 XYabcdY 169 0: XYabcdY 170 1: a 171 2: b 172 3: <unset> 173 4: <unset> 174 5: c 175 6: d 176 7: Y 177 178 /(?'abc'\w+):\k<abc>{2}/ 179 a:aaxyz 180 0: a:aa 181 1: a 182 ab:ababxyz 183 0: ab:abab 184 1: ab 185 ** Failers 186 No match 187 a:axyz 188 No match 189 ab:abxyz 190 No match 191 192 /(?'abc'\w+):\g{abc}{2}/ 193 a:aaxyz 194 0: a:aa 195 1: a 196 ab:ababxyz 197 0: ab:abab 198 1: ab 199 ** Failers 200 No match 201 a:axyz 202 No match 203 ab:abxyz 204 No match 205 206 /^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x 207 abd 208 0: abd 209 1: a 210 ce 211 0: ce 212 213 /^(a.)\g-1Z/ 214 aXaXZ 215 0: aXaXZ 216 1: aX 217 218 /^(a.)\g{-1}Z/ 219 aXaXZ 220 0: aXaXZ 221 1: aX 222 223 /^(?(DEFINE) (?<A> a) (?<B> b) ) (?&A) (?&B) /x 224 abcd 225 0: ab 226 227 /(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT)) 228 (?(DEFINE) 229 (?<NAME_PAT>[a-z]+) 230 (?<ADDRESS_PAT>\d+) 231 )/x 232 metcalfe 33 233 0: metcalfe 33 234 1: metcalfe 235 2: 33 236 237 /(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/ 238 1.2.3.4 239 0: 1.2.3.4 240 1: <unset> 241 2: .4 242 131.111.10.206 243 0: 131.111.10.206 244 1: <unset> 245 2: .206 246 10.0.0.0 247 0: 10.0.0.0 248 1: <unset> 249 2: .0 250 ** Failers 251 No match 252 10.6 253 No match 254 455.3.4.5 255 No match 256 257 /\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/ 258 1.2.3.4 259 0: 1.2.3.4 260 1: .4 261 131.111.10.206 262 0: 131.111.10.206 263 1: .206 264 10.0.0.0 265 0: 10.0.0.0 266 1: .0 267 ** Failers 268 No match 269 10.6 270 No match 271 455.3.4.5 272 No match 273 274 /^(\w++|\s++)*$/ 275 now is the time for all good men to come to the aid of the party 276 0: now is the time for all good men to come to the aid of the party 277 1: party 278 *** Failers 279 No match 280 this is not a line with only words and spaces! 281 No match 282 283 /(\d++)(\w)/ 284 12345a 285 0: 12345a 286 1: 12345 287 2: a 288 *** Failers 289 No match 290 12345+ 291 No match 292 293 /a++b/ 294 aaab 295 0: aaab 296 297 /(a++b)/ 298 aaab 299 0: aaab 300 1: aaab 301 302 /(a++)b/ 303 aaab 304 0: aaab 305 1: aaa 306 307 /([^()]++|\([^()]*\))+/ 308 ((abc(ade)ufh()()x 309 0: abc(ade)ufh()()x 310 1: x 311 312 /\(([^()]++|\([^()]+\))+\)/ 313 (abc) 314 0: (abc) 315 1: abc 316 (abc(def)xyz) 317 0: (abc(def)xyz) 318 1: xyz 319 *** Failers 320 No match 321 ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 322 No match 323 324 /^([^()]|\((?1)*\))*$/ 325 abc 326 0: abc 327 1: c 328 a(b)c 329 0: a(b)c 330 1: c 331 a(b(c))d 332 0: a(b(c))d 333 1: d 334 *** Failers) 335 No match 336 a(b(c)d 337 No match 338 339 /^>abc>([^()]|\((?1)*\))*<xyz<$/ 340 >abc>123<xyz< 341 0: >abc>123<xyz< 342 1: 3 343 >abc>1(2)3<xyz< 344 0: >abc>1(2)3<xyz< 345 1: 3 346 >abc>(1(2)3)<xyz< 347 0: >abc>(1(2)3)<xyz< 348 1: (1(2)3) 349 350 /^(?:((.)(?1)\2|)|((.)(?3)\4|.))$/i 351 1221 352 0: 1221 353 1: 1221 354 2: 1 355 Satanoscillatemymetallicsonatas 356 0: Satanoscillatemymetallicsonatas 357 1: <unset> 358 2: <unset> 359 3: Satanoscillatemymetallicsonatas 360 4: S 361 AmanaplanacanalPanama 362 0: AmanaplanacanalPanama 363 1: <unset> 364 2: <unset> 365 3: AmanaplanacanalPanama 366 4: A 367 AblewasIereIsawElba 368 0: AblewasIereIsawElba 369 1: <unset> 370 2: <unset> 371 3: AblewasIereIsawElba 372 4: A 373 *** Failers 374 No match 375 Thequickbrownfox 376 No match 377 378 /^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/ 379 12 380 0: 12 381 1: 12 382 (((2+2)*-3)-7) 383 0: (((2+2)*-3)-7) 384 1: (((2+2)*-3)-7) 385 2: - 386 -12 387 0: -12 388 1: -12 389 *** Failers 390 No match 391 ((2+2)*-3)-7) 392 No match 393 394 /^(x(y|(?1){2})z)/ 395 xyz 396 0: xyz 397 1: xyz 398 2: y 399 xxyzxyzz 400 0: xxyzxyzz 401 1: xxyzxyzz 402 2: xyzxyz 403 *** Failers 404 No match 405 xxyzz 406 No match 407 xxyzxyzxyzz 408 No match 409 410 /((< (?: (?(R) \d++ | [^<>]*+) | (?2)) * >))/x 411 <> 412 0: <> 413 1: <> 414 2: <> 415 <abcd> 416 0: <abcd> 417 1: <abcd> 418 2: <abcd> 419 <abc <123> hij> 420 0: <abc <123> hij> 421 1: <abc <123> hij> 422 2: <abc <123> hij> 423 <abc <def> hij> 424 0: <def> 425 1: <def> 426 2: <def> 427 <abc<>def> 428 0: <abc<>def> 429 1: <abc<>def> 430 2: <abc<>def> 431 <abc<> 432 0: <> 433 1: <> 434 2: <> 435 *** Failers 436 No match 437 <abc 438 No match 439 440 /^a+(*FAIL)/ 441 aaaaaa 442 No match 443 444 /a+b?c+(*FAIL)/ 445 aaabccc 446 No match 447 448 /a+b?(*PRUNE)c+(*FAIL)/ 449 aaabccc 450 No match 451 452 /a+b?(*COMMIT)c+(*FAIL)/ 453 aaabccc 454 No match 455 456 /a+b?(*SKIP)c+(*FAIL)/ 457 aaabcccaaabccc 458 No match 459 460 /^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/ 461 aaaxxxxxx 462 0: aaaxxxxxx 463 aaa++++++ 464 0: aaa 465 bbbxxxxx 466 0: bbbxxxxx 467 bbb+++++ 468 0: bbb 469 cccxxxx 470 0: cccxxxx 471 ccc++++ 472 0: ccc 473 dddddddd 474 0: ddd 475 476 /^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/ 477 aaaxxxxxx 478 0: aaaxxxxxx 479 1: aaaxxxxxx 480 aaa++++++ 481 0: aaa 482 1: aaa 483 bbbxxxxx 484 0: bbbxxxxx 485 1: bbbxxxxx 486 bbb+++++ 487 0: bbb 488 1: bbb 489 cccxxxx 490 0: cccxxxx 491 1: cccxxxx 492 ccc++++ 493 0: ccc 494 1: ccc 495 dddddddd 496 0: ddd 497 1: ddd 498 499 /a+b?(*THEN)c+(*FAIL)/ 500 aaabccc 501 No match 502 503 /(A (A|B(*ACCEPT)|C) D)(E)/x 504 ABX 505 0: AB 506 1: AB 507 2: B 508 AADE 509 0: AADE 510 1: AAD 511 2: A 512 3: E 513 ACDE 514 0: ACDE 515 1: ACD 516 2: C 517 3: E 518 ** Failers 519 No match 520 AD 521 No match 522 523 /^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$/i 524 1221 525 0: 1221 526 1: 1221 527 2: 1 528 Satan, oscillate my metallic sonatas! 529 0: Satan, oscillate my metallic sonatas! 530 1: <unset> 531 2: <unset> 532 3: Satan, oscillate my metallic sonatas 533 4: S 534 A man, a plan, a canal: Panama! 535 0: A man, a plan, a canal: Panama! 536 1: <unset> 537 2: <unset> 538 3: A man, a plan, a canal: Panama 539 4: A 540 Able was I ere I saw Elba. 541 0: Able was I ere I saw Elba. 542 1: <unset> 543 2: <unset> 544 3: Able was I ere I saw Elba 545 4: A 546 *** Failers 547 No match 548 The quick brown fox 549 No match 550 551 /^((.)(?1)\2|.)$/ 552 a 553 0: a 554 1: a 555 aba 556 0: aba 557 1: aba 558 2: a 559 aabaa 560 0: aabaa 561 1: aabaa 562 2: a 563 abcdcba 564 0: abcdcba 565 1: abcdcba 566 2: a 567 pqaabaaqp 568 0: pqaabaaqp 569 1: pqaabaaqp 570 2: p 571 ablewasiereisawelba 572 0: ablewasiereisawelba 573 1: ablewasiereisawelba 574 2: a 575 rhubarb 576 No match 577 the quick brown fox 578 No match 579 580 /(a)(?<=b(?1))/ 581 baz 582 0: a 583 1: a 584 ** Failers 585 No match 586 caz 587 No match 588 589 /(?<=b(?1))(a)/ 590 zbaaz 591 0: a 592 1: a 593 ** Failers 594 No match 595 aaa 596 No match 597 598 /(?<X>a)(?<=b(?&X))/ 599 baz 600 0: a 601 1: a 602 603 /^(?|(abc)|(def))\1/ 604 abcabc 605 0: abcabc 606 1: abc 607 defdef 608 0: defdef 609 1: def 610 ** Failers 611 No match 612 abcdef 613 No match 614 defabc 615 No match 616 617 /^(?|(abc)|(def))(?1)/ 618 abcabc 619 0: abcabc 620 1: abc 621 defabc 622 0: defabc 623 1: def 624 ** Failers 625 No match 626 defdef 627 No match 628 abcdef 629 No match 630 631 /(?:a(?<quote> (?<apostrophe>')|(?<realquote>")) |b(?<quote> (?<apostrophe>')|(?<realquote>")) ) (?('quote')[a-z]+|[0-9]+)/xJ 632 a\"aaaaa 633 0: a"aaaaa 634 1: " 635 2: <unset> 636 3: " 637 b\"aaaaa 638 0: b"aaaaa 639 1: <unset> 640 2: <unset> 641 3: <unset> 642 4: " 643 5: <unset> 644 6: " 645 ** Failers 646 No match 647 b\"11111 648 No match 649 650 /(?:(?1)|B)(A(*F)|C)/ 651 ABCD 652 0: BC 653 1: C 654 CCD 655 0: CC 656 1: C 657 ** Failers 658 No match 659 CAD 660 No match 661 662 /^(?:(?1)|B)(A(*F)|C)/ 663 CCD 664 0: CC 665 1: C 666 BCD 667 0: BC 668 1: C 669 ** Failers 670 No match 671 ABCD 672 No match 673 CAD 674 No match 675 BAD 676 No match 677 678 /(?:(?1)|B)(A(*ACCEPT)XX|C)D/ 679 AAD 680 0: AA 681 1: A 682 ACD 683 0: ACD 684 1: C 685 BAD 686 0: BA 687 1: A 688 BCD 689 0: BCD 690 1: C 691 BAX 692 0: BA 693 1: A 694 ** Failers 695 No match 696 ACX 697 No match 698 ABC 699 No match 700 701 /(?(DEFINE)(A))B(?1)C/ 702 BAC 703 0: BAC 704 705 /(?(DEFINE)((A)\2))B(?1)C/ 706 BAAC 707 0: BAAC 708 709 /(?<pn> \( ( [^()]++ | (?&pn) )* \) )/x 710 (ab(cd)ef) 711 0: (ab(cd)ef) 712 1: (ab(cd)ef) 713 2: ef 714 715 /^(?!a(*SKIP)b)/ 716 ac 717 0: 718 719 /^(?=a(*SKIP)b|ac)/ 720 ** Failers 721 No match 722 ac 723 No match 724 725 /^(?=a(*THEN)b|ac)/ 726 ac 727 0: 728 729 /^(?=a(*PRUNE)b)/ 730 ab 731 0: 732 ** Failers 733 No match 734 ac 735 No match 736 737 /^(?=a(*ACCEPT)b)/ 738 ac 739 0: 740 741 /^(?(?!a(*SKIP)b))/ 742 ac 743 0: 744 745 /(?>a\Kb)/ 746 ab 747 0: b 748 749 /((?>a\Kb))/ 750 ab 751 0: b 752 1: ab 753 754 /(a\Kb)/ 755 ab 756 0: b 757 1: ab 758 759 /^a\Kcz|ac/ 760 ac 761 0: ac 762 763 /(?>a\Kbz|ab)/ 764 ab 765 0: ab 766 767 /^(?&t)(?(DEFINE)(?<t>a\Kb))$/ 768 ab 769 0: b 770 771 /^([^()]|\((?1)*\))*$/ 772 a(b)c 773 0: a(b)c 774 1: c 775 a(b(c)d)e 776 0: a(b(c)d)e 777 1: e 778 779 /(?P<L1>(?P<L2>0)(?P>L1)|(?P>L2))/ 780 0 781 0: 0 782 1: 0 783 00 784 0: 00 785 1: 00 786 2: 0 787 0000 788 0: 0000 789 1: 0000 790 2: 0 791 792 /(?P<L1>(?P<L2>0)|(?P>L2)(?P>L1))/ 793 0 794 0: 0 795 1: 0 796 2: 0 797 00 798 0: 0 799 1: 0 800 2: 0 801 0000 802 0: 0 803 1: 0 804 2: 0 805 806 /--- This one does fail, as expected, in Perl. It needs the complex item at the 807 end of the pattern. A single letter instead of (B|D) makes it not fail, 808 which I think is a Perl bug. --- / 809 810 /A(*COMMIT)(B|D)/ 811 ACABX 812 No match 813 814 /--- Check the use of names for failure ---/ 815 816 /^(A(*PRUNE:A)B|C(*PRUNE:B)D)/K 817 ** Failers 818 No match 819 AC 820 No match, mark = A 821 CB 822 No match, mark = B 823 824 /(*MARK:A)(*SKIP:B)(C|X)/K 825 C 826 0: C 827 1: C 828 MK: A 829 D 830 No match, mark = A 831 832 /^(A(*THEN:A)B|C(*THEN:B)D)/K 833 ** Failers 834 No match 835 CB 836 No match, mark = B 837 838 /^(?:A(*THEN:A)B|C(*THEN:B)D)/K 839 CB 840 No match, mark = B 841 842 /^(?>A(*THEN:A)B|C(*THEN:B)D)/K 843 CB 844 No match, mark = B 845 846 /--- This should succeed, as the skip causes bump to offset 1 (the mark). Note 847 that we have to have something complicated such as (B|Z) at the end because, 848 for Perl, a simple character somehow causes an unwanted optimization to mess 849 with the handling of backtracking verbs. ---/ 850 851 /A(*MARK:A)A+(*SKIP:A)(B|Z) | AC/xK 852 AAAC 853 0: AC 854 855 /--- Test skipping over a non-matching mark. ---/ 856 857 /A(*MARK:A)A+(*MARK:B)(*SKIP:A)(B|Z) | AC/xK 858 AAAC 859 0: AC 860 861 /--- Check shorthand for MARK ---/ 862 863 /A(*:A)A+(*SKIP:A)(B|Z) | AC/xK 864 AAAC 865 0: AC 866 867 /--- Don't loop! ---/ 868 869 /(*:A)A+(*SKIP:A)(B|Z)/K 870 AAAC 871 No match, mark = A 872 873 /--- This should succeed, as a non-existent skip name disables the skip ---/ 874 875 /A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/xK 876 AAAC 877 0: AC 878 879 /A(*MARK:A)A+(*SKIP:B)(B|Z) | AC(*:B)/xK 880 AAAC 881 0: AC 882 MK: B 883 884 /--- We use something more complicated than individual letters here, because 885 that causes different behaviour in Perl. Perhaps it disables some optimization; 886 anyway, the result now matches PCRE in that no tag is passed back for the 887 failures. ---/ 888 889 /(A|P)(*:A)(B|P) | (X|P)(X|P)(*:B)(Y|P)/xK 890 AABC 891 0: AB 892 1: A 893 2: B 894 MK: A 895 XXYZ 896 0: XXY 897 1: <unset> 898 2: <unset> 899 3: X 900 4: X 901 5: Y 902 MK: B 903 ** Failers 904 No match 905 XAQQ 906 No match 907 XAQQXZZ 908 No match 909 AXQQQ 910 No match 911 AXXQQQ 912 No match 913 914 /--- COMMIT at the start of a pattern should act like an anchor. Again, 915 however, we need the complication for Perl. ---/ 916 917 /(*COMMIT)(A|P)(B|P)(C|P)/ 918 ABCDEFG 919 0: ABC 920 1: A 921 2: B 922 3: C 923 ** Failers 924 No match 925 DEFGABC 926 No match 927 928 /--- COMMIT inside an atomic group can't stop backtracking over the group. ---/ 929 930 /(\w+)(?>b(*COMMIT))\w{2}/ 931 abbb 932 0: abbb 933 1: a 934 935 /(\w+)b(*COMMIT)\w{2}/ 936 abbb 937 No match 938 939 /--- Check opening parens in comment when seeking forward reference. ---/ 940 941 /(?&t)(?#()(?(DEFINE)(?<t>a))/ 942 bac 943 0: a 944 945 /--- COMMIT should override THEN ---/ 946 947 /(?>(*COMMIT)(?>yes|no)(*THEN)(*F))?/ 948 yes 949 No match 950 951 /(?>(*COMMIT)(yes|no)(*THEN)(*F))?/ 952 yes 953 No match 954 955 /^((yes|no)(*THEN)(*F))?/ 956 yes 957 0: 958 959 /b?(*SKIP)c/ 960 bc 961 0: bc 962 abc 963 0: bc 964 965 /(*SKIP)bc/ 966 a 967 No match 968 969 /(*SKIP)b/ 970 a 971 No match 972 973 /(?P<abn>(?P=abn)xxx|)+/ 974 xxx 975 0: 976 1: 977 978 /-- End of testinput11 --/ 979