Text::Glob - match globbing patterns against text
use Text::Glob qw( match_glob glob_to_regex ); print "matched\n" if match_glob( "foo.*", "foo.bar" ); # prints foo.bar and foo.baz my $regex = glob_to_regex( "foo.*" ); for ( qw( foo.bar foo.baz foo bar ) ) { print "matched: $_\n" if /$regex/; }
Text::Glob implements glob(3) style matching that can be used to match against text, rather than fetching names from a filesystem. If you want to do full file globbing use the File::Glob module instead.
Returns the list of things which match the glob from the source list.
Returns a compiled regex which is the equivalent of the globbing pattern.
Returns a regex string which is the equivalent of the globbing pattern.
The following metacharacters and rules are respected.
*
a* matches a, aa, aaaa and many many more.
a*
a
aa
aaaa
?
a? matches aa, but not a, or aaa
a?
aaa
example.[ch] matches example.c and example.h
example.[ch]
example.c
example.h
demo.[a-c] matches demo.a, demo.b, and demo.c
demo.[a-c]
demo.a
demo.b
demo.c
example.{foo,bar,baz} matches example.foo, example.bar, and example.baz
example.{foo,bar,baz}
example.foo
example.bar
example.baz
*.foo does not match .bar.foo. For this you must either specify the leading . in the glob pattern (.*.foo), or set $Text::Glob::strict_leading_dot to a false value while compiling the regex.
*.foo
.bar.foo
.*.foo
$Text::Glob::strict_leading_dot
/
*.foo does not match bar/baz.foo. For this you must either explicitly match the / in the glob (*/*.foo), or set $Text::Glob::strict_wildcard_slash to a false value while compiling the regex, or change the seperator that Text::Glob uses by setting $Text::Glob::seperator to an alternative value while compiling the the regex.
bar/baz.foo
*/*.foo
$Text::Glob::strict_wildcard_slash
$Text::Glob::seperator
The code uses qr// to produce compiled regexes, therefore this module requires perl version 5.005_03 or newer.
Richard Clamp <richardc@unixbeard.net>
Copyright (C) 2002, 2003, 2006, 2007 Richard Clamp. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
File::Glob, glob(3)
To install Text::Glob, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Glob
CPAN shell
perl -MCPAN -e shell install Text::Glob
For more information on module installation, please visit the detailed CPAN module installation guide.