Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 1 | \section{Standard Module \sectcode{fnmatch}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-fnmatch} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 3 | \stmodindex{fnmatch} |
| 4 | |
| 5 | This module provides support for Unix shell-style wildcards, which are |
Guido van Rossum | 8e94489 | 1997-12-30 04:43:36 +0000 | [diff] [blame] | 6 | \emph{not} the same as regular expressions (which are |
Guido van Rossum | c0cc635 | 1997-12-15 17:53:31 +0000 | [diff] [blame] | 7 | documented in the \code{re} module). The special characters used |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 8 | in shell-style wildcards are: |
| 9 | \begin{itemize} |
| 10 | \item[\code{*}] matches everything |
| 11 | \item[\code{?}] matches any single character |
| 12 | \item[\code{[}\var{seq}\code{]}] matches any character in \var{seq} |
| 13 | \item[\code{[!}\var{seq}\code{]}] matches any character not in \var{seq} |
| 14 | \end{itemize} |
| 15 | |
| 16 | Note that the filename separator (\code{'/'} on Unix) is \emph{not} |
| 17 | special to this module. See module \code{glob} for pathname expansion |
| 18 | (\code{glob} uses \code{fnmatch} to match filename segments). |
| 19 | |
Fred Drake | 798654f | 1997-11-30 05:53:22 +0000 | [diff] [blame] | 20 | \renewcommand{\indexsubitem}{(in module fnmatch)} |
| 21 | |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 22 | \begin{funcdesc}{fnmatch}{filename\, pattern} |
| 23 | Test whether the \var{filename} string matches the \var{pattern} |
| 24 | string, returning true or false. If the operating system is |
| 25 | case-insensitive, then both parameters will be normalized to all |
| 26 | lower- or upper-case before the comparision is performed. If you |
| 27 | require a case-sensitive comparision regardless of whether that's |
| 28 | standard for your operating system, use \code{fnmatchcase()} instead. |
| 29 | \end{funcdesc} |
| 30 | |
| 31 | \begin{funcdesc}{fnmatchcase}{} |
| 32 | Test whether \var{filename} matches \var{pattern}, returning true or |
| 33 | false; the comparision is case-sensitive. |
| 34 | \end{funcdesc} |
| 35 | |
| 36 | \begin{funcdesc}{translate}{pattern} |
| 37 | Translate a shell pattern into a corresponding regular expression, |
| 38 | returning a string describing the pattern. It does not compile the |
Guido van Rossum | 8e94489 | 1997-12-30 04:43:36 +0000 | [diff] [blame] | 39 | expression. \strong{Version note:} in Python 1.4 and earlier, this |
| 40 | function translated to \code{regex} (Emacs style) regular expressions; |
| 41 | in 1.5 and later, it translates to \code{re} (Perl style) regular |
| 42 | expressions. |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 43 | \end{funcdesc} |
| 44 | |