1 //
2 // Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
3 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 //
5 // This code is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 only, as
7 // published by the Free Software Foundation.
8 //
9 // This code is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 // version 2 for more details (a copy is included in the LICENSE file that
13 // accompanied this code).
14 //
15 // You should have received a copy of the GNU General Public License version
16 // 2 along with this work; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 // or visit www.oracle.com if you need additional information or have any
21 // questions.
22 //
23 //
24 // This file contains test cases for regular expressions.
25 // A test case consists of three lines:
26 // The first line is a pattern used in the test
27 // The second line is the input to search for the pattern in
28 // The third line is a concatentation of the match, the number of groups,
29 // and the contents of the first four subexpressions.
30 // Empty lines and lines beginning with comment slashes are ignored.
31 //
32 // Test unsetting of backed off groups
33 ^(a)?a
34 a
35 true a 1
36
37 ^(aa(bb)?)+$
38 aabbaa
39 true aabbaa 2 aa bb
40
41 ((a|b)?b)+
42 b
43 true b 2 b
44
45 (aaa)?aaa
46 aaa
47 true aaa 1
48
49 ^(a(b)?)+$
50 aba
51 true aba 2 a b
52
53 ^(a(b(c)?)?)?abc
54 abc
55 true abc 3
56
57 ^(a(b(c))).*
58 abc
59 true abc 3 abc bc c
60
61 // use of x modifier
62 abc(?x)blah
63 abcblah
64 true abcblah 0
65
66 abc(?x) blah
67 abcblah
68 true abcblah 0
69
70 abc(?x) blah blech
71 abcblahblech
72 true abcblahblech 0
73
74 abc(?x) blah # ignore comment
75 abcblah
76 true abcblah 0
733 true ab9c 0
734
735 \d\d\d
736 blah45
737 false 0
738
739 // Test the caret metacharacter
740 ^abc
741 abcdef
742 true abc 0
743
744 ^abc
745 bcdabc
746 false 0
747
748 // Greedy ? metacharacter
749 a?b
750 aaaab
751 true ab 0
752
753 a?b
754 b
755 true b 0
756
757 a?b
758 aaaccc
759 false 0
760
761 .?b
762 aaaab
763 true ab 0
764
765 // Reluctant ? metacharacter
766 a??b
767 aaaab
768 true ab 0
769
770 a??b
771 b
772 true b 0
773
774 a??b
775 aaaccc
776 false 0
777
778 .??b
779 aaaab
780 true ab 0
781
782 // Possessive ? metacharacter
783 a?+b
784 aaaab
785 true ab 0
786
787 a?+b
788 b
789 true b 0
790
791 a?+b
792 aaaccc
793 false 0
794
795 .?+b
796 aaaab
797 true ab 0
798
799 // Greedy + metacharacter
800 a+b
801 aaaab
802 true aaaab 0
803
804 a+b
805 b
806 false 0
807
808 a+b
809 aaaccc
810 false 0
811
812 .+b
813 aaaab
814 true aaaab 0
815
816 // Reluctant + metacharacter
817 a+?b
818 aaaab
1136 #
1137 true # 0
1138
1139 [\043]+
1140 blahblah#blech
1141 true # 0
1142
1143 [\042-\044]+
1144 blahblah#blech
1145 true # 0
1146
1147 [\u1234-\u1236]
1148 blahblah\u1235blech
1149 true \u1235 0
1150
1151 [^\043]*
1152 blahblah#blech
1153 true blahblah 0
1154
1155 (|f)?+
1156 foo
1157 true 1
|
1 //
2 // Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 //
5 // This code is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 only, as
7 // published by the Free Software Foundation.
8 //
9 // This code is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 // version 2 for more details (a copy is included in the LICENSE file that
13 // accompanied this code).
14 //
15 // You should have received a copy of the GNU General Public License version
16 // 2 along with this work; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 // or visit www.oracle.com if you need additional information or have any
21 // questions.
22 //
23 //
24 // This file contains test cases for regular expressions.
25 // A test case consists of three lines:
26 // The first line is a pattern used in the test
27 // The second line is the input to search for the pattern in
28 // The third line is a concatentation of the match, the number of groups,
29 // and the contents of the first four subexpressions.
30 // Empty lines and lines beginning with comment slashes are ignored.
31 //
32 // Test unsetting of backed off groups
33 ^(a)?a
34 a
35 true a 1
36
37 ^(a){0,1}a
38 a
39 true a 1
40
41 ^(aa(bb)?)+$
42 aabbaa
43 true aabbaa 2 aa bb
44
45 ^(aa(bb){0,1})+$
46 aabbaa
47 true aabbaa 2 aa bb
48
49 ((a|b)?b)+
50 b
51 true b 2 b
52
53 ((a|b){0,1}b)+
54 b
55 true b 2 b
56
57 (aaa)?aaa
58 aaa
59 true aaa 1
60
61 (aaa){0,1}aaa
62 aaa
63 true aaa 1
64
65 ^(a(b)?)+$
66 aba
67 true aba 2 a b
68
69 ^(a(b){0,1})+$
70 aba
71 true aba 2 a b
72
73 ^(a(b(c)?)?)?abc
74 abc
75 true abc 3
76
77 ^(a(b(c){0,1}){0,1}){0,1}abc
78 abc
79 true abc 3
80
81 ^(a(b(c))).*
82 abc
83 true abc 3 abc bc c
84
85 // use of x modifier
86 abc(?x)blah
87 abcblah
88 true abcblah 0
89
90 abc(?x) blah
91 abcblah
92 true abcblah 0
93
94 abc(?x) blah blech
95 abcblahblech
96 true abcblahblech 0
97
98 abc(?x) blah # ignore comment
99 abcblah
100 true abcblah 0
757 true ab9c 0
758
759 \d\d\d
760 blah45
761 false 0
762
763 // Test the caret metacharacter
764 ^abc
765 abcdef
766 true abc 0
767
768 ^abc
769 bcdabc
770 false 0
771
772 // Greedy ? metacharacter
773 a?b
774 aaaab
775 true ab 0
776
777 a{0,1}b
778 aaaab
779 true ab 0
780
781 a?b
782 b
783 true b 0
784
785 a{0,1}b
786 b
787 true b 0
788
789 a?b
790 aaaccc
791 false 0
792
793 a{0,1}b
794 aaaccc
795 false 0
796
797 .?b
798 aaaab
799 true ab 0
800
801 .{0,1}b
802 aaaab
803 true ab 0
804
805 // Reluctant ? metacharacter
806 a??b
807 aaaab
808 true ab 0
809
810 a{0,1}?b
811 aaaab
812 true ab 0
813
814 a??b
815 b
816 true b 0
817
818 a{0,1}?b
819 b
820 true b 0
821
822 a??b
823 aaaccc
824 false 0
825
826 a{0,1}?b
827 aaaccc
828 false 0
829
830 .??b
831 aaaab
832 true ab 0
833
834 .{0,1}?b
835 aaaab
836 true ab 0
837
838 // Possessive ? metacharacter
839 a?+b
840 aaaab
841 true ab 0
842
843 a{0,1}+b
844 aaaab
845 true ab 0
846
847 a?+b
848 b
849 true b 0
850
851 a{0,1}+b
852 b
853 true b 0
854
855 a?+b
856 aaaccc
857 false 0
858
859 a{0,1}+b
860 aaaccc
861 false 0
862
863 .?+b
864 aaaab
865 true ab 0
866
867 .{0,1}+b
868 aaaab
869 true ab 0
870
871 // Greedy + metacharacter
872 a+b
873 aaaab
874 true aaaab 0
875
876 a+b
877 b
878 false 0
879
880 a+b
881 aaaccc
882 false 0
883
884 .+b
885 aaaab
886 true aaaab 0
887
888 // Reluctant + metacharacter
889 a+?b
890 aaaab
1208 #
1209 true # 0
1210
1211 [\043]+
1212 blahblah#blech
1213 true # 0
1214
1215 [\042-\044]+
1216 blahblah#blech
1217 true # 0
1218
1219 [\u1234-\u1236]
1220 blahblah\u1235blech
1221 true \u1235 0
1222
1223 [^\043]*
1224 blahblah#blech
1225 true blahblah 0
1226
1227 (|f)?+
1228 foo
1229 true 1
1230
1231 (|f){0,1}+
1232 foo
1233 true 1
|