Shellish(3pm)
π Regexp::Shellish β Shell-like regular expressions π
okay so bestie, this is the page known as Shellish(3pm), filed under User Contributed Perl Documentation, and it's literally about giving you shell-style wildcards inside Perl regular expressions. let's get into it π«Ά
β¨ SYNOPSIS β¨
use Regexp::Shellish qw( :all ) ;
$re = compile_shellish( 'a/c*d' ) ;
## This next one's like 'a*d' except that it'll
## match 'a/d'.
$re = compile_shellish( 'a**d' ) ;
## And here '**' won't match 'a/d', but behaves
## like 'a*d', except for the possibility of high
## cpu time consumption.
$re = compile_shellish( 'a**d', { star_star => 0 } ) ;
## The next two result in identical $re1 and $re2.
## The second is a noop so that Regexp references can
## be easily accomodated.
$re1 = compile_shellish( 'a{b,c}d' ) ;
$re2 = compile_shellish( qr/\A(?:a(?:b|c)d)\Z/ ) ;
@matches = shellish_glob( $re, @possibilities ) ;
πΈ DESCRIPTION πΈ
so this module hands you shell-like regular expressions. the wildcards you get are "?", "*" and "**", and "**" is like "*" but β plot twist β it also matches "/". the deets live under "compile_shellish".
case sensitivity, plus constructs like <**>, "(a*b)", and "{a,b,c}", can all be disabled. yes, turned off entirely. icons only π
π compile_shellish
compiles a string that holds a 'shellish' regular expression and gives you back a Regexp reference. and if you hand it a Regexp reference? it just passes it right through, unmolested, no notes. π
and here are the transformation rules, shellish on the left, Perl RE on the right, no cap:
*β[^/]*?β.**β.*β unless{ star_star => 0 }...β.*β unless{ dot_dot_dot => 0 }(β(β unless{ parens => 0 })β)β unless{ parens => 0 }{a,b,c}β(?:a|b|c)β unless{ braces => 0 }\aβaβ these are de-escaped and passed toquotemeta()\*β\*β same deal, de-escaped then handed toquotemeta()
the wildcards treat newlines as just normal characters, fr fr. nothing special happening there.
parens group into $1..$n, since they get passed through unmolested (unless you passed the option parens => 0). ngl though, that's useless when you're using glob_shellish().
the final parameter can be a hash reference holding options, like this:
compile_shellish(
'**',
{
anchors => 0, ## Doesn't put ^ and $ around the
## resulting regexp
case_sensitive => 0, ## Make case insensitive
dot_dot_dot => 0, ## '...' is now just three '.' chars
star_star => 0, ## '**' is now two '*' wildcards
parens => 0, ## '(', ')' are now regular chars
braces => 0, ## '{', '}' are now regular chars
}
) ;
and here's each one spelled out, one at a time, because we are thorough in this house:
anchors => 0β doesn't put^and$around the resulting regexpcase_sensitive => 0β makes it case insensitivedot_dot_dot => 0β'...'is now just three'.'charsstar_star => 0β'**'is now two'*'wildcardsparens => 0β'('and')'are now regular charsbraces => 0β'{'and'}'are now regular chars
β οΈ important bestie: no option affects Regexps passed through. like, at all. none of them. periodt.
π¦ shellish_glob
you pass in a regular expression plus a list of possible values, and you get back a list of the values that matched. that's it, that's the whole vibe:
my @matches = shellish_glob( '*/*', @possibilities ) ;
my @matches = shellish_glob( '*/*', @possibilities, \%options ) ;
π AUTHOR π
Barrie Slaymaker <barries@slaysys.com> β absolute icon, we stan π«Ά
okay and for the lil' sign-off, this whole thing is perl v5.36.0, dated 2022-10-13 π happy globbing, bestie, go match some stuff β¨ππ¦
π¦ where this page comes from
- ubuntu noble: libregexp-shellish-perl 0.93-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libregexp-shellish-perl 0.93-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libregexp-shellish-perl 0.93-4 Β· 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