Others have already pointed out the problem with the asterics in your regex. I suspect that you intend to match the middle field if it contains no digits (letters only) or no letters (digits only - the case in all your examples) as well letters followed by digits, but not if the field is empty.
I assume that the asterick after the hyphen is a mistake. You probablly intend to require only one hyphen as a field seperator. Here is an implementation of my assumptions.
use strict; use warnings; use Readonly; Readonly::Scalar my $PREFIX => qr/DOC_/; Readonly::Scalar my $FILTER => qr/ $PREFIX (?: [A-Za-z]+\d* | [A-Za-z]*\d+ ) - [0-9a-z]{3} /x; my @tags = qw( DOC_001_123 DOC_002_214 DOC_001-548 DOC_001-987 ); my @dash_tags = grep {/$FILTER/} @tags; print "@dash_tags\n";
In reply to Re: Regex MATCH
by BillKSmith
in thread Regex MATCH
by stallion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |