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

Re^2: check if string contains anything other than alphanumeric

by Anonymous Monk
on Aug 12, 2007 at 08:25 UTC ( [id://632032]=note: print w/replies, xml ) Need Help??


in reply to Re: check if string contains anything other than alphanumeric
in thread check if string contains anything other than alphanumeric

Yup, ur right. lol, sorry. I was typing very fast and did not even realize it. this did work though:
if ($value =~ m/[^a-zA-Z0-9]/) {
So thank you very much!!!

I do have a question though, why does that work, since it is not !~ and is =~?

Oh well, it does work and that is all that matters!

Thanks again.

Replies are listed 'Best First'.
Re^3: check if string contains anything other than alphanumeric
by FunkyMonk (Chancellor) on Aug 12, 2007 at 09:05 UTC
    If a character class starts with ^, it is a negated character class. That is, it will match any character that is not in the class. So, /[^a-zA-Z0-9]/ will match any character that is not a letter or digit.

    See perlretut for a tutorial on regexps and perlre for the details.

    update: My 200th node :)

Re^3: check if string contains anything other than alphanumeric
by naikonta (Curate) on Aug 12, 2007 at 09:41 UTC
    I do have a question though, why does that work, since it is not !~ and is =~?
    It reads more or less "it's true if the string contains (=~) something other (^) than letters and numbers (a-zA-Z0-9)", so it works.

    You can of course use !~ as well, to say "it's true if the string doesn't contains (!~) one or more letters and numbers ([a-zA-Z0-9]+) in its entirety (hence the ^ and $ that constitutes the start and end marks).

    print "bad string: $string\n" if $string !~ /^[a-zA-Z0-9]+$/;
    which I prefer to write (yes back to =~ and not !~):
    print "bad string: $string\n" unless $string =~ /^[a-zA-Z0-9]+$/;

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-25 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found