I have been struggling with a regular expression involving path names. Immediately, this is a bit troublesome, owing to the embedded / in the pattern, but braces to the rescue.
First the convention I have imposed:
Every path in the set looks like:
/ifmxdev/files/file.0123
but that top directory can take a suffix, for example:
/ifmxdev_test/files/file.8765
The final suffix is exactly 4 digits
After much struggle and an hour of composing this plea, as well as my own thoughts, I came up with a truly ugly but working pattern:
$rawfile_pattern = qr{/ifmxdev[_0-9A-Za-z]*/files/file.\d{4}};
if (! $fname =~ $rawfile_pattern) {....
Now I'd just like some help in making that pattern more elegant, mainly compacting that bracketed section of the regex.
\w
for that character class:qr{/ifmxdev\w*/files/file\.\d{4}};
. And don't forget to escape the period in the suffix. Finally, might want to add some anchors^
and$
, but that's up to you. \$\endgroup\$