diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2016-01-11 22:07:23 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2016-01-11 22:07:23 (GMT) |
commit | 50ba447ab73658a71275cb15f5da3cae5db1de56 (patch) | |
tree | a7c37797c0716cc0106775472268d1ba167e947a /Doc/howto/regex.rst | |
parent | 167c33672500502c979eeb0a9b4bd7cdd57c0efd (diff) | |
download | cpython-50ba447ab73658a71275cb15f5da3cae5db1de56.zip cpython-50ba447ab73658a71275cb15f5da3cae5db1de56.tar.gz cpython-50ba447ab73658a71275cb15f5da3cae5db1de56.tar.bz2 |
#25517: fix regex in the regex howto. Patch by Elena Oat.
Diffstat (limited to 'Doc/howto/regex.rst')
-rw-r--r-- | Doc/howto/regex.rst | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index 2f552e3..cc45e6e 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -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 |