Text::Glob3pm
Match globbing patterns against text
Usage
use Text::Glob qw( match_glob glob_to_regex );print "matched\n" if match_glob( "foo.*", "foo.bar" );# prints foo.bar and foo.bazmy $regex = glob_to_regex( "foo.*" );for ( qw( foo.bar foo.baz foo bar ) ) {print "matched: $_\n" if /$regex/;}
The following metacharacters and rules are respected.
- "*" - match zero or more characters
-
"a*"matches"a","aa","aaaa"and many many more.
- "?" - match exactly one character
-
"a?"matches"aa", but not"a", or"aaa"
- Character sets/ranges
-
"example.[ch]"matches"example.c"and"example.h""demo.[a-c]"matches"demo.a","demo.b", and"demo.c"
- alternation
-
"example.{foo,bar,baz}"matches"example.foo","example.bar", and"example.baz"
- leading . must be explicitly matched
-
"*.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_dotto a false value while compiling the regex.
- "*" and "?" do not match the seperator (i.e. do not match "/")
-
"*.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_slashto a false value while compiling the regex, or change the seperator that Text::Glob uses by setting$Text::Glob::seperatorto an alternative value while compiling the the regex.
Overview
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.
Routines
match_glob( $glob, @things_to_test )
|
Returns the list of things which match the glob from the source list. |
|---|---|
glob_to_regex( $glob )
|
Returns a compiled regex which is the equivalent of the globbing pattern. |
glob_to_regex_string( $glob )
|
Returns a regex string which is the equivalent of the globbing pattern. |
Releases
12 releases since Debian 3.1 (Sarge); the text changed 8 times.