blob: b1f3a1b9b2f3af4ce9cdbc36d08b29873776b62b [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{fnmatch}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{fnmatch}
3
4\modulesynopsis{\UNIX{} shell style pathname pattern matching.}
5
Guido van Rossume76b7a81997-04-27 21:25:52 +00006
Fred Drake48022db1998-01-11 19:06:37 +00007This module provides support for \UNIX{} shell-style wildcards, which
8are \emph{not} the same as regular expressions (which are documented
Fred Drake009ab921998-02-16 21:37:58 +00009in the \module{re}\refstmodindex{re} module). The special characters
Fred Drake48022db1998-01-11 19:06:37 +000010used in shell-style wildcards are:
Fred Drake009ab921998-02-16 21:37:58 +000011
12\begin{list}{}{\leftmargin 0.5in \labelwidth 0.45in}
Guido van Rossume76b7a81997-04-27 21:25:52 +000013\item[\code{*}] matches everything
14\item[\code{?}] matches any single character
15\item[\code{[}\var{seq}\code{]}] matches any character in \var{seq}
16\item[\code{[!}\var{seq}\code{]}] matches any character not in \var{seq}
Fred Drake009ab921998-02-16 21:37:58 +000017\end{list}
Guido van Rossume76b7a81997-04-27 21:25:52 +000018
Fred Drake48022db1998-01-11 19:06:37 +000019Note that the filename separator (\code{'/'} on \UNIX{}) is \emph{not}
20special to this module. See module \code{glob}\refstmodindex{glob}
Fred Drake009ab921998-02-16 21:37:58 +000021for pathname expansion (\module{glob} uses \function{fnmatch()} to
Fred Drake48022db1998-01-11 19:06:37 +000022match filename segments).
Guido van Rossume76b7a81997-04-27 21:25:52 +000023
Fred Drake798654f1997-11-30 05:53:22 +000024
Fred Drake48022db1998-01-11 19:06:37 +000025\begin{funcdesc}{fnmatch}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000026Test whether the \var{filename} string matches the \var{pattern}
27string, returning true or false. If the operating system is
28case-insensitive, then both parameters will be normalized to all
29lower- or upper-case before the comparision is performed. If you
30require a case-sensitive comparision regardless of whether that's
Fred Drake009ab921998-02-16 21:37:58 +000031standard for your operating system, use \function{fnmatchcase()}
32instead.
Guido van Rossume76b7a81997-04-27 21:25:52 +000033\end{funcdesc}
34
Fred Drake48022db1998-01-11 19:06:37 +000035\begin{funcdesc}{fnmatchcase}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000036Test whether \var{filename} matches \var{pattern}, returning true or
37false; the comparision is case-sensitive.
38\end{funcdesc}
39
Fred Drake48022db1998-01-11 19:06:37 +000040\begin{seealso}
Fred Drake48022db1998-01-11 19:06:37 +000041\seemodule{glob}{Shell-style path expansion}
42\end{seealso}