diff --git a/ChangeLog b/ChangeLog
index ff460eb51a456ee1a368ea975531d58256905d7b..06a252f4ae6b4b96156152ec39e041b3f8e17143 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,11 @@ CVS code -
 	- Move the call to raw() on systems that don't define
 	  _POSIX_VDISABLE outside the main input/output loop, as it
 	  doesn't need to be called every time through the loop. (DLR)
+- search.c:
+  do_replace_loop()
+	- Fix segfault when doing a regex replace of a string that
+	  matches inside a line (e.g. replace the "b" in "abc" with
+	  anything). (David Benbennick)
 - winio.c:
   do_credits()
 	- Use nanosleep() instead of usleep().  The latter is only
diff --git a/src/search.c b/src/search.c
index 51d73aa154530c1bede3dfccfe096473acabc0b8..69f9eba210fb38ef5c69f93f58df8e6b43bc1b2a 100644
--- a/src/search.c
+++ b/src/search.c
@@ -722,7 +722,7 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
 #ifdef HAVE_REGEX_H
 	/* Set the bol_eol flag if we're doing a bol and/or eol regex
 	 * replace ("^", "$", or "^$"). */
-	if (ISSET(USE_REGEXP) && regexec(&search_regexp, prevanswer, 1, NULL, REG_NOTBOL | REG_NOTEOL) == REG_NOMATCH)
+	if (ISSET(USE_REGEXP) && regexec(&search_regexp, prevanswer, 0, NULL, REG_NOTBOL | REG_NOTEOL) == REG_NOMATCH)
 	    bol_eol = 1;
 #endif