in reply to Building regexp from a 'mask' string of placeholders.
Then the following should do what you want:
This just replaces the '@' in the string with the capturing '(\d+)' and then does the match. You don't even need the '.' as delimiters - as long as you can ensure that there are only non-digits left and right of the '@'.my $pattern = shift @ARGV; my $name = shift @ARGV; # quotemeta is important to quote all the special # regex chars in the filename pattern $pattern = quotemeta $pattern; # the @ got escaped to '\@' so we have to look for # this sequence instead $pattern =~ s/\\@/(\\d+)/; die 'more than one "@" in pattern' if $pattern =~ tr/@//; my ($number) = $name =~ /^$pattern$/; print $number, $/;
-- Hofmator
|
|---|