Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Regex help

by jreades (Friar)
on Nov 16, 2002 at 13:58 UTC ( #213394=note: print w/ replies, xml ) Need Help??


in reply to Regex help

If you want anything that isn't a digit or a leter (or an underscore), then you might consider using: \W

while ($in =~ /\W/) { # do something }

Or:

while ($in !~ /\w/) { ... }

Otherwise:

while ($in =~ /[^a-zA-Z0-9]/) { # do something }

Or:

while ($in !~ /[a-zA-Z0-9]/) { ... }

There's not much to chose between =~ and !~, but I generally like the emphasis of saying "as long as it's not one of these things..."


Comment on Re: Regex help
Select or Download Code
Re: Re: Regex help
by fruiture (Curate) on Nov 17, 2002 at 12:00 UTC

    Carefull with logic!

    $in =~ /\W/ # is NOT the same as $in !~ /\w/
    --
    http://fruiture.de

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-27 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls