Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 romping around the Monastery: (10)
As of 2015-07-06 07:04 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 (70 votes), past polls