@@ -917,12 +917,12 @@ extension RegexTests {
917
917
input: " Price: 100 pesos " , match: " 100 " )
918
918
919
919
// More complex lookaheads
920
- firstMatchTest (
921
- #"(?=.*e)(?=.*o)(?!.*z)"# ,
922
- input: " hello " , match: " " )
923
- firstMatchTest (
924
- #"^(?=.*e)(?=.*o)(?!.*h)"# ,
925
- input: " hello " , match: nil )
920
+ firstMatchTests (
921
+ #"(?=.*e)(?=.*o)(?!.*z). "# ,
922
+ ( input: " hello " , match: " h " ) ,
923
+ ( input : " hzello " , match : " e " ) ,
924
+ ( input : " hezllo " , match : nil ) ,
925
+ ( input: " helloz " , match: nil ) )
926
926
927
927
firstMatchTest (
928
928
#"(?<=USD)\d+"# , input: " Price: USD100 " , match: " 100 " , xfail: true )
@@ -1069,18 +1069,43 @@ extension RegexTests {
1069
1069
firstMatchTest (
1070
1070
#"(?:(?>a)|.b)c"# , input: " 123abcacxyz " , match: " abc " )
1071
1071
1072
- // Quantifier behavior inside atomic
1073
- firstMatchTest (
1074
- #"^(?>a+?)a$"# , input: " aa " , match: " aa " )
1075
- firstMatchTest (
1076
- #"^(?>a+?)a$"# , input: " aaa " , match: nil )
1077
- firstMatchTest (
1078
- #"(?>a++)a"# , input: " aaa " , match: nil )
1072
+ // Quantifier behavior inside atomic groups
1073
+
1074
+ // (?:a+?) matches as few 'a's as possible, after matching the first
1075
+ // (?>a+?) always matches exactly one 'a'
1076
+ firstMatchTests (
1077
+ #"^(?:a+?)a$"# ,
1078
+ ( input: " a " , match: nil ) ,
1079
+ ( input: " aa " , match: " aa " ) ,
1080
+ ( input: " aaa " , match: " aaa " ) )
1081
+ firstMatchTests (
1082
+ #"^(?>a+?)a$"# ,
1083
+ ( input: " a " , match: nil ) ,
1084
+ ( input: " aa " , match: " aa " ) ,
1085
+ ( input: " aaa " , match: nil ) )
1086
+
1087
+ // (?:a?+) and (?>a?+) are equivalent: they match one 'a' if available
1088
+ firstMatchTests (
1089
+ #"^(?:a?+)a$"# ,
1090
+ ( input: " a " , match: nil ) ,
1091
+ xfail: true )
1092
+ firstMatchTests (
1093
+ #"^(?:a?+)a$"# ,
1094
+ ( input: " aa " , match: " aa " ) ,
1095
+ ( input: " aaa " , match: nil ) )
1096
+ firstMatchTests (
1097
+ #"^(?>a?+)a$"# ,
1098
+ ( input: " a " , match: nil ) ,
1099
+ ( input: " aa " , match: " aa " ) ,
1100
+ ( input: " aaa " , match: nil ) )
1079
1101
1080
- firstMatchTest (
1081
- #"(?>(\d+))\w+\1"# , input: " 123x12 " , match: nil )
1082
- firstMatchTest (
1083
- #"(?>(\d+))\w+\1"# , input: " 123x23 " , match: " 23x23 " ,
1102
+ firstMatchTests (
1103
+ #"(?>(\d+))\w+\1"# ,
1104
+ ( input: " 123x12 " , match: nil ) )
1105
+ firstMatchTests (
1106
+ #"(?>(\d+))\w+\1"# ,
1107
+ ( input: " 23x23 " , match: " 23x23 " ) ,
1108
+ ( input: " 123x23 " , match: " 23x23 " ) ,
1084
1109
xfail: true )
1085
1110
1086
1111
// TODO: Test example where non-atomic is significant
0 commit comments