Text::Glob(3)
π Text::Glob(3) β bestie edition
Okay so real talk: this is the Text::Glob(3) manual page, and it's about matching globbing patterns against text β not against your filesystem. Buckle up, it's actually so good.
β¨ NAME β¨
Text::Glob β match globbing patterns against text π
πΈ SYNOPSIS πΈ
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/;
}
π DESCRIPTION π
So Text::Glob implements glob(3)-style matching, but here's the twist β it matches against text, not by going and fetching actual names out of a filesystem. It's giving "glob energy, but make it stringy." β¨
Heads up bestie: if you want to do full file globbing, use the File::Glob module instead. This one is not that. π«Ά
π§ Routines
match_glob( $glob, @things_to_test )β gives you back the list of things from the source list that match the glob. Slay.glob_to_regex( $glob )β gives you back a compiled regex that's the equivalent of the globbing pattern.glob_to_regex_string( $glob )β gives you back a regex string that's the equivalent of the globbing pattern. (Yes, a string, not a compiled regex. Both exist. Iconic.)
π₯ SYNTAX π₯
These are the metacharacters and rules that are respected:
*β matches zero or more charactersa*matchesa,aa,aaaaand like, many many more. infinite vibes.
?β matches exactly one charactera?matchesaa, but nota, and notaaa. one (1) character, periodt.
- Character sets/ranges
example.[ch]matchesexample.candexample.hdemo.[a-c]matchesdemo.a,demo.b, anddemo.c
- alternation
example.{foo,bar,baz}matchesexample.foo,example.bar, andexample.baz
- leading
.must be explicitly matched*.foodoes 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. they do not match/)*.foodoes not matchbar/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 thatText::Globuses by setting$Text::Glob::seperatorto an alternative value while compiling the the regex.
π BUGS π
The code uses qr// to produce compiled regexes, therefore this module requires perl version 5.005_03 or newer. That's the whole bug note. No cap.
π AUTHOR π
Richard Clamp <richardc@unixbeard.net>
π COPYRIGHT π
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.
π¦ SEE ALSO π¦
File::Glob, glob(3)
And that's the whole page, bestie β brought to you by perl v5.42.0, dated 2025-05-20. Go forth and match some globs π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Text-Glob 0.110.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms