You asked them for an interface that would seem to not have enough flexibility.... Why not give them a syntax like:
# & = words & digits (alphanumeric) # @ = digits # # = word chars ie [a-zA-Z_] # . = literal . used to separate parts of interest # Anything else is taken to be literal in meaning my $str = "some-file.123.tif"; my $find_str = qq!some-#.@.&!; print "Here is our filename: $str\nHere is the interface string: $find +_str\n"; my @bits = split '\.', $find_str; for (@bits) { s/([^&@#a-zA-Z_])/\\$1/g; s/&/\\w*/g; s/@/\\d*/g; s/#/[a-zA-Z_]*/g; $_ = "($_)"; } my $re = join "\\.", @bits; print "Here is the RE: m/$re/"; $re = qr/$re/; my (@matches) = $str =~ m/^$re$/; $" = ', '; print "\nAnd we got: @matches"; __DATA__ Here is our filename: some-file.123.tif Here is the interface string: some-#.@.& Here is the RE: m/(some\-[a-zA-Z_]*)\.(\d*)\.(\w*)/ And we got: some-file, 123, tif
The syntax is pretty basic - just three chars for word, dogit and alphanumeric. . for the separator. all other chars are literal. This gives you a lot of power to match subsets of filenames and should take no more that 2 minutes to learn....
Changed " token to # so you don't have to escape it in the shell as pointed out by waswas-fng
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Re: Re: Building regexp from a 'mask' string of placeholders.
by tachyon
in thread Building regexp from a 'mask' string of placeholders.
by submersible_toaster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |