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