Index: /FCKeditor/trunk/editor/dialog/fck_replace.html
===================================================================
--- /FCKeditor/trunk/editor/dialog/fck_replace.html	(revision 1686)
+++ /FCKeditor/trunk/editor/dialog/fck_replace.html	(revision 1687)
@@ -232,7 +232,6 @@
 // Knuth-Morris-Pratt Algorithm for stream input
 KMP_NOMATCH = 0 ;
-KMP_STARTED = 1 ;
-KMP_ADVANCED = 2 ;
-KMP_MATCHED = 3 ;
+KMP_ADVANCED = 1 ;
+KMP_MATCHED = 2 ;
 function KmpMatch( pattern, ignoreCase )
 {
@@ -269,5 +268,5 @@
 					return KMP_MATCHED;
 				}
-				return this._State > 1 ? KMP_ADVANCED : KMP_STARTED ;
+				return KMP_ADVANCED ;
 			}
 			else if ( this._State == 0 )
@@ -292,4 +291,5 @@
 	var matchState = KMP_NOMATCH ;
 	var matchBookmark = null ;
+	var matchBookmarkStart = [] ;
 
 	// Match finding.
@@ -306,5 +306,5 @@
 				{
 					matcher.Reset();
-					matchBookmark = null ;
+					matchBookmarkStart = [] ;
 				}
 			}
@@ -316,17 +316,21 @@
 				// So delete any positional information.
 				if ( matchState == KMP_NOMATCH )
-					matchBookmark = null ;
-				// The currently scanned character is a possible start, so mark down the starting position.
-				else if ( matchState == KMP_STARTED )
-					matchBookmark = { Start : cursor.concat( [] ) } ;
+					matchBookmarkStart = [] ;
+				// We've matched something, but it's not a complete match, so let's just mark down the position for backtracking later.
+				else if ( matchState == KMP_ADVANCED )
+				{
+					matchBookmarkStart.push( cursor.concat( [] ) ) ;
+					if ( matchBookmarkStart.length > matcher._State )
+						matchBookmarkStart.shift() ;
+				}
 				// Found a complete match! Mark down the ending position as well.
 				else if ( matchState == KMP_MATCHED )
 				{
-					// It is possible to get a KMP_MATCHED without KMP_STARTED when the match pattern is only 1 character.
+					// It is possible to get a KMP_MATCHED without KMP_ADVANCED when the match pattern is only 1 character.
 					// So need to check and mark down the starting position as well.
-					if ( matchBookmark == null )
-						matchBookmark = { Start : cursor.concat( [] ) } ;
-
-					matchBookmark.End = cursor.concat( [] ) ;
+					if ( matchBookmarkStart.length == 0 )
+						matchBookmarkStart = [cursor.concat( [] )] ;
+
+					matchBookmark = { 'Start' : matchBookmarkStart.shift(), 'End' : cursor.concat( [] ) } ;
 					matchBookmark.End[ matchBookmark.End.length - 1 ]++;
 
