Catman...::Regex(3pm)
β¨ NAME β¨
Catmandu::Util::Regex β regex-related utility functions π straight out of the Catman...::Regex(3pm) page in the User Contributed Perl Documentation. Bestie, it's giving "tiny module, big helper energy" and we're obsessed. π
πΈ FUNCTIONS πΈ
π¦ as_regex($str)
Escapes and quotes the string you hand it, so it comes back out as a regex. That's it, that's the whole job, and it does it flawlessly. β¨
π substituter($search, $replace)
Builds you a function that performs a regex substitution. You give it the search pattern and the replace string, and it hands back a little closure that does the substituting whenever you call it. Main character behavior, honestly. π
Check it out:
my $ltrimmer = substituter('^[\h\v]+', '');
$ltrimmer->(" eek! ");
# => "eek! "
So like, $ltrimmer is a thing now, and you just call $ltrimmer->(...) on a string and the leading horizontal/vertical whitespace gets yeeted into the void. " eek! " walks in, "eek! " walks out. No cap, it just works. π
okay that's the whole page, bestie, you ate it π«Ά this was perl v5.40.1, dated 2026-01-24, and yes we're still calling the whole thing Catman...::Regex(3pm) π bye, go write some regex πβ¨
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms