FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] Docs: Add missing lines between regex and text (GH-134505) by miss-islington · Pull Request #135718 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 6 additions & 2 deletions Doc/howto/regex.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,9 @@ extension. This regular expression matches ``foo.bar`` and
Now, consider complicating the problem a bit; what if you want to match
filenames where the extension is not ``bat``? Some incorrect attempts:

``.*[.][^b].*$`` The first attempt above tries to exclude ``bat`` by requiring
``.*[.][^b].*$``

The first attempt above tries to exclude ``bat`` by requiring
that the first character of the extension is not a ``b``. This is wrong,
because the pattern also doesn't match ``foo.bar``.

Expand All @@ -1043,7 +1045,9 @@ 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
Expand Down

Back | FazBrowse Home | New Git URL