blob: 7d974611383a02a884ce9fc7a5e0f576aa013374 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{fnmatch} ---
Fred Drake06a73f01999-06-10 21:23:31 +00002 \UNIX{} 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 Drake06a73f01999-06-10 21:23:31 +000022special to this module. See module
23\refmodule{glob}\refstmodindex{glob} for pathname expansion
24(\refmodule{glob} uses \function{fnmatch()} to match filename
25segments).
Guido van Rossume76b7a81997-04-27 21:25:52 +000026
Fred Drake798654f1997-11-30 05:53:22 +000027
Fred Drake48022db1998-01-11 19:06:37 +000028\begin{funcdesc}{fnmatch}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000029Test whether the \var{filename} string matches the \var{pattern}
30string, returning true or false. If the operating system is
31case-insensitive, then both parameters will be normalized to all
32lower- or upper-case before the comparision is performed. If you
33require a case-sensitive comparision regardless of whether that's
Fred Drake009ab921998-02-16 21:37:58 +000034standard for your operating system, use \function{fnmatchcase()}
35instead.
Guido van Rossume76b7a81997-04-27 21:25:52 +000036\end{funcdesc}
37
Fred Drake48022db1998-01-11 19:06:37 +000038\begin{funcdesc}{fnmatchcase}{filename, pattern}
Guido van Rossume76b7a81997-04-27 21:25:52 +000039Test whether \var{filename} matches \var{pattern}, returning true or
40false; the comparision is case-sensitive.
41\end{funcdesc}
42
Fred Drake8d2c0c21999-03-16 16:40:01 +000043
Fred Drake48022db1998-01-11 19:06:37 +000044\begin{seealso}
Fred Drake8d2c0c21999-03-16 16:40:01 +000045 \seemodule{glob}{Shell-style path expansion}
Fred Drake48022db1998-01-11 19:06:37 +000046\end{seealso}