Skip to content

Add missing lines between regex and text #134505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Doc/howto/regex.rst
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
Loading