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