8000 GH-101112: Add "pattern language" section to pathlib docs by barneygale · Pull Request #114030 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-101112: Add "pattern language" section to pathlib docs #114030

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

Merged
merged 18 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Convert to table, add examples.
  • Loading branch information
barneygale committed Jan 26, 2024
commit 9fe2866c22a8328b3708ec80ccb67e804400e9be
32 changes: 20 additions & 12 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1634,22 +1634,30 @@ Pattern language
The following wildcards are supported in patterns for
:meth:`~PurePath.full_match`, :meth:`~Path.glob` and :meth:`~Path.rglob`:

"``**``" (standalone segment)
Matches any number of file or directory segments.
"``*``" (standalone segment)
Matches one non-empty file or directory segment.
"``*``" (otherwise)
Matches any number of non-separator characters.
"``?``"
Matches one non-separator character.
"``[seq]``"
Matches one character in *seq*.
"``[!seq]``"
Matches one character not in *seq*.
========================= ===========================================
Wildcard Matches
========================= ===========================================
"``**``" (full segment) Any number of file or directory segments.
"``*``" (full segment) One file or directory segment.
"``*``" (otherwise) Any number of non-separator characters.
"``?``" One non-separator character.
"``[seq]``" One character in *seq*.
"``[!seq]``" One character not in *seq*.
========================= ===========================================

For a literal match, wrap the meta-characters in brackets.
For example, ``"[?]"`` matches the character ``"?"``.

The "``**``" wildcard enables recursive globbing:

========================= ===========================================
Pattern Meaning
========================= ===========================================
``"**/*"`` Any path with at least one segment.
``"**/*.py"`` Any path with a final segment ending ``".py"``.
``"assets/**"`` Any path starting with ``"assets/"``.
``"assets/**/*"`` Any path starting with ``"assets/"``, excluding ``"assets/"`` itself.


Correspondence to tools in the :mod:`os` module
-----------------------------------------------
Expand Down
0