1Text::Glob(3) User Contributed Perl Documentation Text::Glob(3)
2
3
4
6 Text::Glob - match globbing patterns against text
7
9 use Text::Glob qw( match_glob glob_to_regex );
10
11 print "matched\n" if match_glob( "foo.*", "foo.bar" );
12
13 # prints foo.bar and foo.baz
14 my $regex = glob_to_regex( "foo.*" );
15 for ( qw( foo.bar foo.baz foo bar ) ) {
16 print "matched: $_\n" if /$regex/;
17 }
18
20 Text::Glob implements glob(3) style matching that can be used to match
21 against text, rather than fetching names from a filesystem. If you
22 want to do full file globbing use the File::Glob module instead.
23
24 Routines
25 match_glob( $glob, @things_to_test )
26 Returns the list of things which match the glob from the source
27 list.
28
29 glob_to_regex( $glob )
30 Returns a compiled regex which is the equivalent of the globbing
31 pattern.
32
33 glob_to_regex_string( $glob )
34 Returns a regex string which is the equivalent of the globbing
35 pattern.
36
38 The following metacharacters and rules are respected.
39
40 "*" - match zero or more characters
41 "a*" matches "a", "aa", "aaaa" and many many more.
42
43 "?" - match exactly one character
44 "a?" matches "aa", but not "a", or "aaa"
45
46 Character sets/ranges
47 "example.[ch]" matches "example.c" and "example.h"
48
49 "demo.[a-c]" matches "demo.a", "demo.b", and "demo.c"
50
51 alternation
52 "example.{foo,bar,baz}" matches "example.foo", "example.bar", and
53 "example.baz"
54
55 leading . must be explicitly matched
56 "*.foo" does not match ".bar.foo". For this you must either
57 specify the leading . in the glob pattern (".*.foo"), or set
58 $Text::Glob::strict_leading_dot to a false value while compiling
59 the regex.
60
61 "*" and "?" do not match the seperator (i.e. do not match "/")
62 "*.foo" does not match "bar/baz.foo". For this you must either
63 explicitly match the / in the glob ("*/*.foo"), or set
64 $Text::Glob::strict_wildcard_slash to a false value while compiling
65 the regex, or change the seperator that Text::Glob uses by setting
66 $Text::Glob::seperator to an alternative value while compiling the
67 the regex.
68
70 The code uses qr// to produce compiled regexes, therefore this module
71 requires perl version 5.005_03 or newer.
72
74 Richard Clamp <richardc@unixbeard.net>
75
77 Copyright (C) 2002, 2003, 2006, 2007 Richard Clamp. All Rights
78 Reserved.
79
80 This module is free software; you can redistribute it and/or modify it
81 under the same terms as Perl itself.
82
84 File::Glob, glob(3)
85
86
87
88perl v5.26.3 2017-03-08 Text::Glob(3)