Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{fnmatch}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-fnmatch} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 3 | \stmodindex{fnmatch} |
| 4 | |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 5 | This module provides support for \UNIX{} shell-style wildcards, which |
| 6 | are \emph{not} the same as regular expressions (which are documented |
Fred Drake | 009ab92 | 1998-02-16 21:37:58 +0000 | [diff] [blame] | 7 | in the \module{re}\refstmodindex{re} module). The special characters |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 8 | used in shell-style wildcards are: |
Fred Drake | 009ab92 | 1998-02-16 21:37:58 +0000 | [diff] [blame] | 9 | |
| 10 | \begin{list}{}{\leftmargin 0.5in \labelwidth 0.45in} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 11 | \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 Drake | 009ab92 | 1998-02-16 21:37:58 +0000 | [diff] [blame] | 15 | \end{list} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 16 | |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 17 | Note that the filename separator (\code{'/'} on \UNIX{}) is \emph{not} |
| 18 | special to this module. See module \code{glob}\refstmodindex{glob} |
Fred Drake | 009ab92 | 1998-02-16 21:37:58 +0000 | [diff] [blame] | 19 | for pathname expansion (\module{glob} uses \function{fnmatch()} to |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 20 | match filename segments). |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 21 | |
Fred Drake | 798654f | 1997-11-30 05:53:22 +0000 | [diff] [blame] | 22 | |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 23 | \begin{funcdesc}{fnmatch}{filename, pattern} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 24 | Test whether the \var{filename} string matches the \var{pattern} |
| 25 | string, returning true or false. If the operating system is |
| 26 | case-insensitive, then both parameters will be normalized to all |
| 27 | lower- or upper-case before the comparision is performed. If you |
| 28 | require a case-sensitive comparision regardless of whether that's |
Fred Drake | 009ab92 | 1998-02-16 21:37:58 +0000 | [diff] [blame] | 29 | standard for your operating system, use \function{fnmatchcase()} |
| 30 | instead. |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 31 | \end{funcdesc} |
| 32 | |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 33 | \begin{funcdesc}{fnmatchcase}{filename, pattern} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 34 | Test whether \var{filename} matches \var{pattern}, returning true or |
| 35 | false; the comparision is case-sensitive. |
| 36 | \end{funcdesc} |
| 37 | |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 38 | \begin{seealso} |
Fred Drake | 48022db | 1998-01-11 19:06:37 +0000 | [diff] [blame] | 39 | \seemodule{glob}{Shell-style path expansion} |
| 40 | \end{seealso} |