Browse Source

fixed in case of unmatched group at the end

Nicolas Cannasse 17 years ago
parent
commit
5c1a9519a0
1 changed files with 6 additions and 6 deletions
  1. 6 6
      std/EReg.hx

+ 6 - 6
std/EReg.hx

@@ -123,12 +123,12 @@ class EReg {
 		#elseif flash9
 			return untyped if( result != null && n >= 0 && n < result.length ) result[n] else throw "EReg::matched";
 		#elseif php
-			if(n >= 0 && n < matches.length) {
-				if(matches[n][1] < 0) return null;
-				return matches[n][0];
-			}
-			//else return null;
-			else throw "EReg::matched";
+			if( n < 0 ) throw "EReg::matched";
+			// we can't differenciate between optional groups at the end of a match
+			// that have not been matched and invalid groups
+			if( n >= matches.length ) return null;
+			if(matches[n][1] < 0) return null;
+			return matches[n][0];
 		#else
 			return null;
 		#end