blob: f2f82bafeb92e39286f341cdf82dc266d526fda1 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{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
Fred Drake48022db1998-01-11 19:06:37 +00005This module provides support for \UNIX{} shell-style wildcards, which
6are \emph{not} the same as regular expressions (which are documented
Fred Drake009ab921998-02-16 21:37:58 +00007in the \module{re}\refstmodindex{re} module). The special characters
Fred Drake48022db1998-01-11 19:06:37 +00008used in shell-style wildcards are:
Fred Drake009ab921998-02-16 21:37:58 +00009
10\begin{list}{}{\leftmargin 0.5in \labelwidth 0.45in}
Guido van Rossume76b7a81997-04-27 21:25:52 +000011\item[\code{*}] matches everything
12\item[\code{?}] matches any single character
13\item[\code{[}\var{seq}\code{]}] matches any character in \var{seq}
14\item[\code{[!}\var{seq}\code{]}] matches any character not in \var{seq}
Fred Drake009ab921998-02-16 21:37:58 +000015\end{list}
Guido van Rossume76b7a81997-04-27 21:25:52 +000016
Fred Drake48022db1998-01-11 19:06:37 +000017Note that the filename separator (\code{'/'} on \UNIX{}) is \emph{not}
18special to this module. See module \code{glob}\refstmodindex{glob}
Fred Drake009ab921998-02-16 21:37:58 +000019for pathname expansion (\module{glob} uses \function{fnmatch()} to
Fred Drake48022db1998-01-11 19:06:37 +000020match filename segments).
Guido van Rossume76b7a81997-04-27 21:25:52 +000021
Fred Drake798654f1997-11-30 05:53:22 +000022
Fred Drake48022db1998-01-11 19:06:37 +000023\begin{funcdesc}{fnmatch}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000024Test whether the \var{filename} string matches the \var{pattern}
25string, returning true or false. If the operating system is
26case-insensitive, then both parameters will be normalized to all
27lower- or upper-case before the comparision is performed. If you
28require a case-sensitive comparision regardless of whether that's
Fred Drake009ab921998-02-16 21:37:58 +000029standard for your operating system, use \function{fnmatchcase()}
30instead.
Guido van Rossume76b7a81997-04-27 21:25:52 +000031\end{funcdesc}
32
Fred Drake48022db1998-01-11 19:06:37 +000033\begin{funcdesc}{fnmatchcase}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000034Test whether \var{filename} matches \var{pattern}, returning true or
35false; the comparision is case-sensitive.
36\end{funcdesc}
37
Fred Drake48022db1998-01-11 19:06:37 +000038\begin{seealso}
Fred Drake48022db1998-01-11 19:06:37 +000039\seemodule{glob}{Shell-style path expansion}
40\end{seealso}