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....

Update

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.