blob: 824ee44a26d95ac57cf95317f12eb66cfd49f627 [file] [log] [blame]
Guido van Rossume76b7a81997-04-27 21:25:52 +00001\section{Standard Module \sectcode{fnmatch}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-fnmatch}
Guido van Rossume76b7a81997-04-27 21:25:52 +00003\stmodindex{fnmatch}
4
5This module provides support for Unix shell-style wildcards, which are
Guido van Rossum8e944891997-12-30 04:43:36 +00006\emph{not} the same as regular expressions (which are
Guido van Rossumc0cc6351997-12-15 17:53:31 +00007documented in the \code{re} module). The special characters used
Guido van Rossume76b7a81997-04-27 21:25:52 +00008in 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
16Note that the filename separator (\code{'/'} on Unix) is \emph{not}
17special to this module. See module \code{glob} for pathname expansion
18(\code{glob} uses \code{fnmatch} to match filename segments).
19
Fred Drake798654f1997-11-30 05:53:22 +000020\renewcommand{\indexsubitem}{(in module fnmatch)}
21
Guido van Rossume76b7a81997-04-27 21:25:52 +000022\begin{funcdesc}{fnmatch}{filename\, pattern}
23Test whether the \var{filename} string matches the \var{pattern}
24string, returning true or false. If the operating system is
25case-insensitive, then both parameters will be normalized to all
26lower- or upper-case before the comparision is performed. If you
27require a case-sensitive comparision regardless of whether that's
28standard for your operating system, use \code{fnmatchcase()} instead.
29\end{funcdesc}
30
31\begin{funcdesc}{fnmatchcase}{}
32Test whether \var{filename} matches \var{pattern}, returning true or
33false; the comparision is case-sensitive.
34\end{funcdesc}
35
36\begin{funcdesc}{translate}{pattern}
37Translate a shell pattern into a corresponding regular expression,
38returning a string describing the pattern. It does not compile the
Guido van Rossum8e944891997-12-30 04:43:36 +000039expression. \strong{Version note:} in Python 1.4 and earlier, this
40function translated to \code{regex} (Emacs style) regular expressions;
41in 1.5 and later, it translates to \code{re} (Perl style) regular
42expressions.
Guido van Rossume76b7a81997-04-27 21:25:52 +000043\end{funcdesc}
44