This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading doc of $ metacharacter in re
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake
Priority: normal Keywords:

Created on 2001-07-16 05:29 by anonymous, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (2)
msg5423 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-07-16 05:29
From: machin_john_888@hotmail.com (John Machin)
Newsgroups: comp.lang.python
Subject: Re: re Challenge: More Compact?
References: <mailman.995247446.16415.python-
list@python.org>
NNTP-Posting-Host: 140.168.16.251
Message-ID: 
<0107152124.4c049d5e@posting.google.com">92ae279c.0107152124.4c049d5e@posting.google.com>

"Tim Peters" <tim.one@home.com> wrote in message 
news:<mailman.995247446.16415.python-
list@python.org>...
> BTW, does it bother anyone that all of these 
solutions accept an IP ending
> with a newline?
> 
> regexps-are-surprising-ly y'rs  - tim

Straight out of the horse's mouth at
http://python.sourceforge.net/devel-docs/lib/re-
syntax.html
(this is in section 4.2.1 of the Python Library 
Reference):
<quote>
"$" 
Matches the end of the string, and in MULTILINE mode 
also matches
before a newline. foo matches both 'foo' and 'foobar', 
while the
regular expression foo$ matches only 'foo'.
</quote>
But the real story only emerges two pages later (in 
section 4.2.3):
<quote>
M 
MULTILINE
When specified, the pattern character "^" matches at 
the beginning of
the string and at the beginning of each line 
(immediately following
each newline); and the pattern character "$" matches 
at the end of the
string and at the end of each line (immediately 
preceding each
newline). By default, "^" matches only at the 
beginning of the string,
and "$" only at the end of the string and immediately 
before the
newline (if any) at the end of the string.
</quote>

I shall enter a bug report and leave it up to the 
powers_that_be to
decide whether to change the behaviour or section 
4.2.1 of the
documentation.

To answer Tim's question, yes it bothers me ... the 
solution of course
always when you want to validate that the pattern 
matches the whole
string (and not some leading substring) is to have \Z 
at the end of
your pattern (not $).

msg5424 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2001-07-23 21:16
Logged In: YES 
user_id=3066

Fixed the documentation in Doc/lib/libre.tex revision 1.64.
History
Date User Action Args
2022-04-10 16:04:12adminsetgithub: 34761
2001-07-16 05:29:23anonymouscreate