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
Simplify presentation.
  • Loading branch information
barneygale committed Jan 26, 2024
commit aa94135f98d03ff969ede55e028dd1922ef713d5
31 changes: 15 additions & 16 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1595,22 +1595,21 @@ call fails (for example because the path doesn't exist).
Pattern language
----------------

:meth:`PurePath.match`, :meth:`Path.glob` and :meth:`Path.rglob` accept
patterns with shell-style wildcards.

The "``**``" wildcard matches any number of file or directory segments. In
other words, it enabled recursive globbing. If "``**``" occurs in any position
other than a full pattern segment, :exc:`ValueError` is raised.

The "``*``" wildcard matches precisely one file or directory segment when it
occurs as a full pattern segment, or any number of non-separator characters
when it occurs elsewhere.

The "``?``" wildcard matches a single non-separator character. Character
ranges such as "``[seq]``" and "``[!seq]``" match a single character within or
without the range.

If the pattern ends with a path separator, only directories are matched.
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*.

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