1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
|
//
// Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
//
// This code is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License version 2 only, as
// published by the Free Software Foundation.
//
// This code is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// version 2 for more details (a copy is included in the LICENSE file that
// accompanied this code).
//
// You should have received a copy of the GNU General Public License version
// 2 along with this work; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
// or visit www.oracle.com if you need additional information or have any
// questions.
//
//
// This file contains test cases for regular expressions.
// A test case consists of three lines:
// The first line is a pattern used in the test
// The second line is the input to search for the pattern in
// The third line is a concatentation of the match, the number of groups,
// and the contents of the first four subexpressions.
// Empty lines and lines beginning with comment slashes are ignored.
//
// Test unsetting of backed off groups
^(a)?a
a
true a 1
^(aa(bb)?)+$
aabbaa
true aabbaa 2 aa bb
((a|b)?b)+
b
true b 2 b
(aaa)?aaa
aaa
true aaa 1
^(a(b)?)+$
aba
true aba 2 a b
^(a(b(c)?)?)?abc
abc
true abc 3
^(a(b(c))).*
abc
true abc 3 abc bc c
// use of x modifier
abc(?x)blah
abcblah
true abcblah 0
abc(?x) blah
abcblah
true abcblah 0
abc(?x) blah blech
abcblahblech
true abcblahblech 0
abc(?x) blah # ignore comment
abcblah
true abcblah 0
// Simple alternation
a|b
a
true a 0
a|b
z
false 0
a|b
b
true b 0
a|b|cd
cd
true cd 0
a|ad
ad
true a 0
z(a|ac)b
zacb
true zacb 1 ac
// Simple char class
[abc]+
ababab
true ababab 0
[abc]+
defg
false 0
[abc]+[def]+[ghi]+
zzzaaddggzzz
true aaddgg 0
// Range char class
[a-g]+
zzzggg
true ggg 0
[a-g]+
mmm
false 0
[a-]+
za-9z
true a- 0
[a-\\u4444]+
za-9z
true za 0
// Negated char class
[^abc]+
ababab
false 0
[^abc]+
aaabbbcccdefg
true defg 0
// Negation with nested char class and intersection
[^[c]]
c
false 0
[^[a-z]]
e
false 0
[^[a-z][A-Z]]
E
false 0
[^a-d[0-9][m-p]]
e
true e 0
[^a-d[0-9][m-p]]
8
false 0
[^[a-c]&&[d-f]]
z
true z 0
[^a-c&&d-f]
a
true a 0
[^a-m&&m-z]
m
false 0
[^a-m&&m-z&&a-c]
m
true m 0
[^a-cd-f&&[d-f]]
c
true c 0
[^[a-c][d-f]&&abc]
a
false 0
[^[a-c][d-f]&&abc]
d
true d 0
[^[a-c][d-f]&&abc[def]]
a
false 0
[^[a-c][d-f]&&abc[def]]
e
false 0
[^[a-c]&&[b-d]&&[c-e]]
a
true a 0
[^[a-c]&&[b-d]&&[c-e]]
c
false 0
// Making sure a ^ not in first position matches literal ^
[abc^b]
b
true b 0
[abc^b]
^
true ^ 0
// Class union and intersection
[abc[def]]
b
true b 0
[abc[def]]
e
true e 0
[a-d[0-9][m-p]]
a
true a 0
[a-d[0-9][m-p]]
o
true o 0
[a-d[0-9][m-p]]
4
true 4 0
[a-d[0-9][m-p]]
e
false 0
[a-d[0-9][m-p]]
u
false 0
[[a-d][0-9][m-p]]
b
true b 0
[[a-d][0-9][m-p]]
z
false 0
[a-c[d-f[g-i]]]
a
true a 0
[a-c[d-f[g-i]]]
e
true e 0
[a-c[d-f[g-i]]]
h
true h 0
[a-c[d-f[g-i]]]
m
false 0
[a-c[d-f[g-i]]m]
m
true m 0
[abc[def]ghi]
a
true a 0
[abc[def]ghi]
d
true d 0
[abc[def]ghi]
h
true h 0
[abc[def]ghi]
w
false 0
[a-c&&[d-f]]
a
false 0
[a-c&&[d-f]]
e
false 0
[a-c&&[d-f]]
z
false 0
[[a-c]&&[d-f]]
a
false 0
[[a-c]&&[d-f]]
e
false 0
[[a-c]&&[d-f]]
z
false 0
[a-c&&d-f]
a
false 0
[a-m&&m-z]
m
true m 0
[a-m&&m-z&&a-c]
m
false 0
[a-m&&m-z&&a-z]
m
true m 0
[[a-m]&&[m-z]]
a
false 0
[[a-m]&&[m-z]]
m
true m 0
[[a-m]&&[m-z]]
z
false 0
[[a-m]&&[^a-c]]
a
false 0
[[a-m]&&[^a-c]]
d
true d 0
[a-m&&[^a-c]]
a
false 0
[a-m&&[^a-c]]
d
true d 0
[a-cd-f&&[d-f]]
a
false 0
[a-cd-f&&[d-f]]
e
true e 0
[[a-c]&&d-fa-c]
a
true a 0
[[a-c]&&[d-f][a-c]]
a
true a 0
[[a-c][d-f]&&abc]
a
true a 0
[[a-c][d-f]&&abc[def]]
e
true e 0
[[a-c]&&[b-d]&&[c-e]]
a
false 0
[[a-c]&&[b-d]&&[c-e]]
c
true c 0
[[a-c]&&[b-d][c-e]&&[u-z]]
c
false 0
[abc[^bcd]]
a
true a 0
[abc[^bcd]]
d
false 0
[a-c&&a-d&&a-eghi]
b
true b 0
[a-c&&a-d&&a-eghi]
g
false 0
[[a[b]]&&[b[a]]]
a
true a 0
[[a]&&[b][c][a]&&[^d]]
a
true a 0
[[a]&&[b][c][a]&&[^d]]
d
false 0
[[[a-d]&&[c-f]]]
a
false 0
[[[a-d]&&[c-f]]]
c
true c 0
[[[a-d]&&[c-f]]&&[c]]
c
true c 0
[[[a-d]&&[c-f]]&&[c]&&c]
c
true c 0
[[[a-d]&&[c-f]]&&[c]&&c&&c]
c
true c 0
[[[a-d]&&[c-f]]&&[c]&&c&&[cde]]
c
true c 0
[z[abc&&bcd]]
c
true c 0
[z[abc&&bcd]&&[u-z]]
z
true z 0
[x[abc&&bcd[z]]&&[u-z]]
z
false 0
[x[[wz]abc&&bcd[z]]&&[u-z]]
z
true z 0
[[abc]&&[def]abc]
a
true a 0
[[abc]&&[def]xyz[abc]]
a
true a 0
\pL
a
true a 0
\pL
7
false 0
\p{L}
a
true a 0
\p{LC}
a
true a 0
\p{LC}
A
true A 0
\p{IsL}
a
true a 0
\p{IsLC}
a
true a 0
\p{IsLC}
A
true A 0
\p{IsLC}
9
false 0
\P{IsLC}
9
true 9 0
// Guillemet left is initial quote punctuation
\p{Pi}
\u00ab
true \u00ab 0
\P{Pi}
\u00ac
true \u00ac 0
// Guillemet right is final quote punctuation
\p{IsPf}
\u00bb
true \u00bb 0
\p{P}
\u00bb
true \u00bb 0
\p{P}+
\u00bb
true \u00bb 0
\P{IsPf}
\u00bc
true \u00bc 0
\P{IsP}
\u00bc
true \u00bc 0
\p{L1}
\u00bc
true \u00bc 0
\p{L1}+
\u00bc
true \u00bc 0
\p{L1}
\u02bc
false 0
\p{ASCII}
a
true a 0
\p{IsASCII}
a
true a 0
\p{IsASCII}
\u0370
false 0
\pLbc
abc
true abc 0
a[r\p{InGreek}]c
a\u0370c
true a\u0370c 0
a\p{InGreek}
a\u0370
true a\u0370 0
a\P{InGreek}
a\u0370
false 0
a\P{InGreek}
ab
true ab 0
a{^InGreek}
-
error
a\p{^InGreek}
-
error
a\P{^InGreek}
-
error
a\p{InGreek}
a\u0370
true a\u0370 0
a[\p{InGreek}]c
a\u0370c
true a\u0370c 0
a[\P{InGreek}]c
a\u0370c
false 0
a[\P{InGreek}]c
abc
true abc 0
a[{^InGreek}]c
anc
true anc 0
a[{^InGreek}]c
azc
false 0
a[\p{^InGreek}]c
-
error
a[\P{^InGreek}]c
-
error
a[\p{InGreek}]
a\u0370
true a\u0370 0
a[r\p{InGreek}]c
arc
true arc 0
a[\p{InGreek}r]c
arc
true arc 0
a[r\p{InGreek}]c
arc
true arc 0
a[^\p{InGreek}]c
a\u0370c
false 0
a[^\P{InGreek}]c
a\u0370c
true a\u0370c 0
a[\p{InGreek}&&[^\u0370]]c
a\u0370c
false 0
// Test the dot metacharacter
a.c.+
a#c%&
true a#c%& 0
ab.
ab\n
false 0
(?s)ab.
ab\n
true ab\n 0
a[\p{L}&&[\P{InGreek}]]c
a\u6000c
true a\u6000c 0
a[\p{L}&&[\P{InGreek}]]c
arc
true arc 0
a[\p{L}&&[\P{InGreek}]]c
a\u0370c
false 0
a\p{InGreek}c
a\u0370c
true a\u0370c 0
a\p{Sc}
a$
true a$ 0
// Test the word char escape sequence
ab\wc
abcc
true abcc 0
\W\w\W
#r#
true #r# 0
\W\w\W
rrrr#ggg
false 0
abc[\w]
abcd
true abcd 0
abc[\sdef]*
abc def
true abc def 0
abc[\sy-z]*
abc y z
true abc y z 0
abc[a-d\sm-p]*
abcaa mn p
true abcaa mn p 0
// Test the whitespace escape sequence
ab\sc
ab c
true ab c 0
\s\s\s
blah err
false 0
\S\S\s
blah err
true ah 0
// Test the digit escape sequence
ab\dc
ab9c
true ab9c 0
\d\d\d
blah45
false 0
// Test the caret metacharacter
^abc
abcdef
true abc 0
^abc
bcdabc
false 0
// Greedy ? metacharacter
a?b
aaaab
true ab 0
a?b
b
true b 0
a?b
aaaccc
false 0
.?b
aaaab
true ab 0
// Reluctant ? metacharacter
a??b
aaaab
true ab 0
a??b
b
true b 0
a??b
aaaccc
false 0
.??b
aaaab
true ab 0
// Possessive ? metacharacter
a?+b
aaaab
true ab 0
a?+b
b
true b 0
a?+b
aaaccc
false 0
.?+b
aaaab
true ab 0
// Greedy + metacharacter
a+b
aaaab
true aaaab 0
a+b
b
false 0
a+b
aaaccc
false 0
.+b
aaaab
true aaaab 0
// Reluctant + metacharacter
a+?b
aaaab
true aaaab 0
a+?b
b
false 0
a+?b
aaaccc
false 0
.+?b
aaaab
true aaaab 0
// Possessive + metacharacter
a++b
aaaab
true aaaab 0
a++b
b
false 0
a++b
aaaccc
false 0
.++b
aaaab
false 0
// Greedy Repetition
a{2,3}
a
false 0
a{2,3}
aa
true aa 0
a{2,3}
aaa
true aaa 0
a{2,3}
aaaa
true aaa 0
a{3,}
zzzaaaazzz
true aaaa 0
a{3,}
zzzaazzz
false 0
// Reluctant Repetition
a{2,3}?
a
false 0
a{2,3}?
aa
true aa 0
a{2,3}?
aaa
true aa 0
a{2,3}?
aaaa
true aa 0
// Zero width Positive lookahead
abc(?=d)
zzzabcd
true abc 0
abc(?=d)
zzzabced
false 0
// Zero width Negative lookahead
abc(?!d)
zzabcd
false 0
abc(?!d)
zzabced
true abc 0
// Zero width Positive lookbehind
\w(?<=a)
###abc###
true a 0
\w(?<=a)
###ert###
false 0
// Zero width Negative lookbehind
(?<!a)\w
###abc###
true a 0
(?<!a)c
bc
true c 0
(?<!a)c
ac
false 0
// Nondeterministic group
(a+b)+
ababab
true ababab 1 ab
(a|b)+
ccccd
false 1
// Deterministic group
(ab)+
ababab
true ababab 1 ab
(ab)+
accccd
false 1
(ab)*
ababab
true ababab 1 ab
(ab)(cd*)
zzzabczzz
true abc 2 ab c
abc(d)*abc
abcdddddabc
true abcdddddabc 1 d
// Escaped metacharacter
\*
*
true * 0
\\
\
true \ 0
\\
\\\\
true \ 0
// Back references
(a*)bc\1
zzzaabcaazzz
true aabcaa 1 aa
(a*)bc\1
zzzaabcazzz
true abca 1 a
(gt*)(dde)*(yu)\1\3(vv)
zzzgttddeddeyugttyuvvzzz
true gttddeddeyugttyuvv 4 gtt dde yu vv
// Greedy * metacharacter
a*b
aaaab
true aaaab 0
a*b
b
true b 0
a*b
aaaccc
false 0
.*b
aaaab
true aaaab 0
// Reluctant * metacharacter
a*?b
aaaab
true aaaab 0
a*?b
b
true b 0
a*?b
aaaccc
false 0
.*?b
aaaab
true aaaab 0
// Possessive * metacharacter
a*+b
aaaab
true aaaab 0
a*+b
b
true b 0
a*+b
aaaccc
false 0
.*+b
aaaab
false 0
// Case insensitivity
(?i)foobar
fOobAr
true fOobAr 0
f(?i)oobar
fOobAr
true fOobAr 0
foo(?i)bar
fOobAr
false 0
(?i)foo[bar]+
foObAr
true foObAr 0
(?i)foo[a-r]+
foObAr
true foObAr 0
// Disable metacharacters- test both length <=3 and >3
// So that the BM optimization is part of test
\Q***\Eabc
***abc
true ***abc 0
bl\Q***\Eabc
bl***abc
true bl***abc 0
\Q***abc
***abc
true ***abc 0
blah\Q***\Eabc
blah***abc
true blah***abc 0
\Q***abc
***abc
true ***abc 0
\Q*ab
*ab
true *ab 0
blah\Q***abc
blah***abc
true blah***abc 0
bla\Q***abc
bla***abc
true bla***abc 0
// Escapes in char classes
[ab\Qdef\E]
d
true d 0
[ab\Q[\E]
[
true [ 0
[\Q]\E]
]
true ] 0
[\Q\\E]
\
true \ 0
[\Q(\E]
(
true ( 0
[\n-#]
!
true ! 0
[\n-#]
-
false 0
[\w-#]
!
false 0
[\w-#]
a
true a 0
[\w-#]
-
true - 0
[\w-#]
#
true # 0
[\043]+
blahblah#blech
true # 0
[\042-\044]+
blahblah#blech
true # 0
[\u1234-\u1236]
blahblah\u1235blech
true \u1235 0
[^\043]*
blahblah#blech
true blahblah 0
(|f)?+
foo
true 1
|