Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Simple regex question

by BrowserUk (Pope)
on Sep 28, 2012 at 18:13 UTC ( #996262=note: print w/replies, xml ) Need Help??

in reply to Simple regex question

Almost exactly the way you described it:

print "$_: ", /^\w+$/ && !/^\d+$/ ? 'Good' : 'Bad' for qw[ abc a1c 1b3 + 123 ];; abc: Good a1c: Good 1b3: Good 123: Bad

Or if you insist on a single regex:

print "$_: ", /^(?=.*[a-zA-z])\w+$/ ? 'Good' : 'Bad' for qw[ abc a1c 1 +b3 123 ];; abc: Good a1c: Good 1b3: Good 123: Bad

Though it is doubtful if it is any more efficient; and is certainly less clear.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996262]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2017-04-30 11:15 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (537 votes). Check out past polls.