CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
regex question

 



darian
Deleted

Feb 16, 2000, 11:47 PM

Post #1 of 4 (733 views)
regex question Can't Post

Will the below code get rid of the following characters? !@#$%^&*()_+-={}|[]\:";'<>?,./~`

Or is there a better way to do it?

$line =~ s/[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\~\`\'\"\:\;\<\>\?\,\.\/\|\\]//;

Or how about this:
if ($line !=~ /[a-zA-Z1-9]/) { print "It has non-alpanumeric characters."; }

Yes someday I promise to learn more about regex. 8~)


darian
Deleted

Feb 17, 2000, 2:23 AM

Post #2 of 4 (733 views)
Re: regex question [In reply to] Can't Post

well my first one works but is there an easier way of doing it?

$line =~ s/[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\~\`\'\"\:\;\<\>\?\,\.\/\|\\]//;

Seems a little long don't you think?


perlkid
stranger

Feb 17, 2000, 3:01 AM

Post #3 of 4 (733 views)
Re: regex question [In reply to] Can't Post

 That's definitly confusing,

I haven't tryed this yet but see if you can use this.

if ($line =~ /\[(\w+)/)
{
print "you have inputed nothing but alphanumeric charachters";
}
else
{
print "stop trying to type in jiberish";
}

You get the idea, without the if condition I suppose you could use this

$line =~ /\[(\w+)/;

let me know if that works.

perlkid



[This message has been edited by perlkid (edited 02-17-2000).]


japhy
Enthusiast

Feb 17, 2000, 4:07 AM

Post #4 of 4 (733 views)
Re: regex question [In reply to] Can't Post

If there is a set of characters you WON'T allow, there is also a set you WILL. Test based on whichever is smaller:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# don't allow , . / < > or ?
if ($string =~ /[,./<>?]/) { bad data }

# don't allow non-alphanumberscores
# that's anything that's not a-zA-Z0-9_
if ($string =~ /\W/) { \W is opposite of \w }
</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives