1FnMatch(3) User Contributed Perl Documentation FnMatch(3)
2
3
4
6 File::FnMatch - simple filename and pathname matching
7
9 use File::FnMatch qw(:fnmatch); # import everything
10
11 # shell-style: match "/a/bc", but not "/a/.bc" nor "/a/b/c"
12 fnmatch("/a/*", $fn, FNM_PATHNAME|FNM_PERIOD);
13
14 # find our A- executables only
15 grep { fnmatch("A-*.exe", $_) } readdir SOMEDIR;
16
18 File::FnMatch::fnmatch() provides simple, shell-like pattern matching.
19
20 Though considerably less powerful than regular expressions, shell
21 patterns are nonetheless useful and familiar to a large audience of
22 end-users.
23
24 Functions
25 fnmatch ( PATTERN, STRING [, FLAGS] )
26 Returns true if PATTERN matches STRING, undef otherwise. FLAGS may
27 be the bitwise OR'ing of any supported FNM_* constants (see below).
28
29 Constants
30 FNM_NOESCAPE
31 Do not treat a backslash ('\') in PATTERN specially. Otherwise, a
32 backslash escapes the following character.
33
34 FNM_PATHNAME
35 Prohibit wildcards from matching a slash ('/').
36
37 FNM_PERIOD
38 Prohibit wildcards from matching a period ('.') at the start of a
39 string and, if FNM_PATHNAME is also given, immediately after a
40 slash.
41
42 Other possibilities include at least FNM_CASEFOLD (compare "qr//i"),
43 FNM_LEADING_DIR to restrict matching to everything before the first
44 '/', FNM_FILE_NAME as a synonym for FNM_PATHNAME, and the rather more
45 exotic FNM_EXTMATCH. Consult your system documentation for details.
46
47 EXPORT
48 None by default. The export tag ":fnmatch" exports the fnmatch
49 function and all available FNM_* constants.
50
52 Wildcards are the question mark ('?') to match any single character and
53 the asterisk ('*') to match zero or more characters. FNM_PATHNAME and
54 FNM_PERIOD restrict the scope of the wildcards, notably supporting the
55 UNIX convention of concealing "dotfiles":
56
57 Bracket expressions, enclosed by '[' and ']', match any of a set of
58 characters specified explicitly ("[abcdef]"), as a range ("[a-f0-9]"),
59 or as the combination these ("[a-f0-9XYZ]"). Additionally, many
60 implementations support named character classes such as "[[:xdigit:]]".
61 Character sets may be negated with an initial '!' ("[![:space:]]").
62
63 Locale influences the meaning of fnmatch() patterns.
64
66 Most UNIX-like systems provide an fnmatch implementation. This module
67 will not work on platforms lacking an implementation, most notably
68 Win32.
69
71 File::Glob, POSIX::setlocale, fnmatch(3)
72
74 Michael J. Pomraning
75
76 Please report bugs to <mjp-perl AT pilcrow.madison.wi.us>
77
79 Copyright 2005 by Michael J. Pomraning
80
81 This library is free software; you can redistribute it and/or modify it
82 under the same terms as Perl itself.
83
84
85
86perl v5.30.1 2020-01-30 FnMatch(3)