Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: regex help

by kcott (Abbot)
on Oct 05, 2013 at 19:38 UTC ( #1057074=note: print w/ replies, xml ) Need Help??


in reply to regex help

G'day kelscat18,

You're using a substitution (i.e. s/pattern/replacement/) when you really want a pattern match (i.e. /pattern/). You're also using the 'g' modifier, which is unnecessary here. Take a look at "perlretut - Perl regular expressions tutorial" to get an understanding of the basics. Here's how I might have coded that (which, I suspect, is close to what Corion had in mind):

#!/usr/bin/env perl use strict; use warnings; my @tests = qw{jHj8nniO I87jjj8y jUjngnkk ikbHH 12345 !@$%^&*}; my @words = grep { /[A-Za-z]/ && /\d/ } @tests; print "@words\n";

Output:

jHj8nniO I87jjj8y

-- Ken


Comment on Re: regex help
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-02 05:31 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 (29 votes), past polls