Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Regex MATCH

by BillKSmith (Deacon)
on Sep 14, 2012 at 14:31 UTC ( #993732=note: print w/ replies, xml ) Need Help??


in reply to Regex MATCH

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";
Bill


Comment on Re: Regex MATCH
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-07-30 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls