Closing issue1761.
Surprising behaviour of the "$" regexp: it matches the
end of the string, AND just before the newline at the end
of the string::
re.sub('$', '#', 'foo\n') == 'foo#\n#'
Python is consistent with Perl and the pcre library, so
we just document it.
Guido prefers "\Z" to match only the end of the string.
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 850e1f8..dd22835 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -98,7 +98,9 @@
string, and in :const:`MULTILINE` mode also matches before a newline. ``foo``
matches both 'foo' and 'foobar', while the regular expression ``foo$`` matches
only 'foo'. More interestingly, searching for ``foo.$`` in ``'foo1\nfoo2\n'``
- matches 'foo2' normally, but 'foo1' in :const:`MULTILINE` mode.
+ matches 'foo2' normally, but 'foo1' in :const:`MULTILINE` mode; searching for
+ a single ``$`` in ``'foo\n'`` will find two (empty) matches: one just before
+ the newline, and one at the end of the string.
``'*'``
Causes the resulting RE to match 0 or more repetitions of the preceding RE, as