]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#25517: fix regex in the regex howto. Patch by Elena Oat.
authorEzio Melotti <ezio.melotti@gmail.com>
Mon, 11 Jan 2016 22:07:23 +0000 (00:07 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Mon, 11 Jan 2016 22:07:23 +0000 (00:07 +0200)
Doc/howto/regex.rst

index 2f552e39a1c930068858422b0e9813ddf92b8ac4..cc45e6e489d75aa962711969cbf222c6e2c828a1 100644 (file)
@@ -1015,17 +1015,18 @@ confusing.
 
 A negative lookahead cuts through all this confusion:
 
-``.*[.](?!bat$).*$``  The negative lookahead means: if the expression ``bat``
+``.*[.](?!bat$)[^.]*$``  The negative lookahead means: if the expression ``bat``
 doesn't match at this point, try the rest of the pattern; if ``bat$`` does
 match, the whole pattern will fail.  The trailing ``$`` is required to ensure
 that something like ``sample.batch``, where the extension only starts with
-``bat``, will be allowed.
+``bat``, will be allowed.  The ``[^.]*`` makes sure that the pattern works
+when there are multiple dots in the filename.
 
 Excluding another filename extension is now easy; simply add it as an
 alternative inside the assertion.  The following pattern excludes filenames that
 end in either ``bat`` or ``exe``:
 
-``.*[.](?!bat$|exe$).*$``
+``.*[.](?!bat$|exe$)[^.]*$``
 
 
 Modifying Strings