blob: ef1033568efffcbf5eaa614435a6500fa7a332ef [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{fnmatch} ---
Fred Drake8d2c0c21999-03-16 16:40:01 +00002 \UNIX{} style filename pattern matching}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake8d2c0c21999-03-16 16:40:01 +00004\declaremodule{standard}{fnmatch}
5\modulesynopsis{\UNIX{} shell style filename pattern matching.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Guido van Rossume76b7a81997-04-27 21:25:52 +00007
Fred Drake48022db1998-01-11 19:06:37 +00008This module provides support for \UNIX{} shell-style wildcards, which
9are \emph{not} the same as regular expressions (which are documented
Fred Drake8d2c0c21999-03-16 16:40:01 +000010in the \refmodule{re}\refstmodindex{re} module). The special
11characters used in shell-style wildcards are:
12\index{filenames!wildcard expansion}
Fred Drake009ab921998-02-16 21:37:58 +000013
14\begin{list}{}{\leftmargin 0.5in \labelwidth 0.45in}
Guido van Rossume76b7a81997-04-27 21:25:52 +000015\item[\code{*}] matches everything
16\item[\code{?}] matches any single character
17\item[\code{[}\var{seq}\code{]}] matches any character in \var{seq}
18\item[\code{[!}\var{seq}\code{]}] matches any character not in \var{seq}
Fred Drake009ab921998-02-16 21:37:58 +000019\end{list}
Guido van Rossume76b7a81997-04-27 21:25:52 +000020
Fred Drake48022db1998-01-11 19:06:37 +000021Note that the filename separator (\code{'/'} on \UNIX{}) is \emph{not}
Fred Drakee688aec1999-04-21 17:04:43 +000022special to this module. See module \refmodule{glob}\refstmodindex{glob}
23for pathname expansion (\refmodule{glob} uses \function{fnmatch()} to
Fred Drake48022db1998-01-11 19:06:37 +000024match filename segments).
Guido van Rossume76b7a81997-04-27 21:25:52 +000025
Fred Drake798654f1997-11-30 05:53:22 +000026
Fred Drake48022db1998-01-11 19:06:37 +000027\begin{funcdesc}{fnmatch}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000028Test whether the \var{filename} string matches the \var{pattern}
29string, returning true or false. If the operating system is
30case-insensitive, then both parameters will be normalized to all
31lower- or upper-case before the comparision is performed. If you
32require a case-sensitive comparision regardless of whether that's
Fred Drake009ab921998-02-16 21:37:58 +000033standard for your operating system, use \function{fnmatchcase()}
34instead.
Guido van Rossume76b7a81997-04-27 21:25:52 +000035\end{funcdesc}
36
Fred Drake48022db1998-01-11 19:06:37 +000037\begin{funcdesc}{fnmatchcase}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000038Test whether \var{filename} matches \var{pattern}, returning true or
39false; the comparision is case-sensitive.
40\end{funcdesc}
41
Fred Drake8d2c0c21999-03-16 16:40:01 +000042
Fred Drake48022db1998-01-11 19:06:37 +000043\begin{seealso}
Fred Drake8d2c0c21999-03-16 16:40:01 +000044 \seemodule{glob}{Shell-style path expansion}
Fred Drake48022db1998-01-11 19:06:37 +000045\end{seealso}