-- changed $ to match before a trailing newline, even
   if the multiline flag isn't given.
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 268c5dd..46fe4ed 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -310,7 +310,9 @@
                 SRE_IS_LINEBREAK((int) ptr[-1]));
 
 	case SRE_AT_END:
-		return ((void*) ptr == state->end);
+        return (((void*) (ptr+1) == state->end &&
+                 SRE_IS_LINEBREAK((int) ptr[0])) ||
+                ((void*) ptr == state->end));
 
 	case SRE_AT_END_LINE:
 		return ((void*) ptr == state->end ||