blob: e5e287197ff8f1ae0506164284d259865a719cfd [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
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 Drake19479911998-02-13 06:58:54 +000022\setindexsubitem{(in module fnmatch)}
Fred Drake798654f1997-11-30 05:53:22 +000023
Fred Drake48022db1998-01-11 19:06:37 +000024\begin{funcdesc}{fnmatch}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000025Test whether the \var{filename} string matches the \var{pattern}
26string, returning true or false. If the operating system is
27case-insensitive, then both parameters will be normalized to all
28lower- or upper-case before the comparision is performed. If you
29require a case-sensitive comparision regardless of whether that's
Fred Drake009ab921998-02-16 21:37:58 +000030standard for your operating system, use \function{fnmatchcase()}
31instead.
Guido van Rossume76b7a81997-04-27 21:25:52 +000032\end{funcdesc}
33
Fred Drake48022db1998-01-11 19:06:37 +000034\begin{funcdesc}{fnmatchcase}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000035Test whether \var{filename} matches \var{pattern}, returning true or
36false; the comparision is case-sensitive.
37\end{funcdesc}
38
Fred Drake48022db1998-01-11 19:06:37 +000039\begin{seealso}
Fred Drake48022db1998-01-11 19:06:37 +000040\seemodule{glob}{Shell-style path expansion}
41\end{seealso}