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:
Strippin characters

 



JonnyThunder
User

Oct 2, 2002, 8:17 AM

Post #1 of 11 (2356 views)
Strippin characters Can't Post

Can anyone tell me a regular expression or a method for stripping characters from a string. I am accepting input from a form, and want to strip anything that isn't A - Z (upper or lower case), Numbers or basic punctuation (such as , and .)

I think this needs to be done with regular expressions, but am not very good with them.

Thanks,
JT


jryan
User

Oct 2, 2002, 8:19 AM

Post #2 of 11 (2349 views)
Re: [JonnyThunder] Strippin characters [In reply to] Can't Post


Code
tr/a-zA-Z0-9.,!?;//cd;



JonnyThunder
User

Oct 2, 2002, 9:07 AM

Post #3 of 11 (2346 views)
Re: [JonnyThunder] Strippin characters [In reply to] Can't Post

Thanks. Will give that a shot.


thebitch
User

Oct 3, 2002, 4:03 AM

Post #4 of 11 (2339 views)
Re: [jryan] Strippin characters [In reply to] Can't Post

In the spirit of s/// and m//, I must ask why? Sly

Code
y/a-zA-Z0-9.,!?;//cd;



jryan
User

Oct 3, 2002, 10:53 AM

Post #5 of 11 (2336 views)
Re: [thebitch] Strippin characters [In reply to] Can't Post

First off, y/// is a synonym for tr///. Secondly, to answer your question, tr/// is faster than s///; s/// invokes the regular expression engine, which is large and bulky, while tr/// does not.


thebitch
User

Oct 4, 2002, 2:46 AM

Post #6 of 11 (2328 views)
Re: [jryan] Strippin characters [In reply to] Can't Post


Code
! jryan->can('humor'); 
! jryan->can('humor');
! jryan->can('humor');
! jryan->can('humor');



Paul
Enthusiast

Oct 4, 2002, 3:13 AM

Post #7 of 11 (2328 views)
Re: [thebitch] Strippin characters [In reply to] Can't Post

thebitch->can('bitch');


jryan
User

Oct 4, 2002, 12:35 PM

Post #8 of 11 (2322 views)
Re: [RedRum] Strippin characters [In reply to] Can't Post

Don't you mean:

Code
thebitch->isa('bitch');



thebitch
User

Oct 5, 2002, 5:55 AM

Post #9 of 11 (2316 views)
Re: [jryan] Strippin characters [In reply to] Can't Post

ooooh, pure genius Tongue


weatherboy
Novice

Oct 7, 2002, 11:18 AM

Post #10 of 11 (2300 views)
Re: [thebitch] Strippin characters [In reply to] Can't Post

but wait you wacky programmer geeks.

original answer was: tr/a-zA-Z0-9.,!?;//cd;

So, how is this implemented? like this:

$fred = tr/a-zA-Z0-9.,!?;//cd;

Is that it?
"I know nothink"
- Schulz, Hogan's Heroes


thebitch
User

Oct 8, 2002, 1:13 AM

Post #11 of 11 (2290 views)
Re: [weatherboy] Strippin characters [In reply to] Can't Post

Well test it out young fellar Wink

Code
$\="\n"; 
$_ = "[Scooooone!]";

print;
$b = tr/a-zA-Z0-9.,!?;//cd;
print;
print $b;

__END__


and now read
`perldoc perlop'
and possibly `perldoc perlfaq' along with `perldoc perlre'

the operator you're looking for is ~ combined with =


Code
$\="\n"; 
$_ = "[Scooooone!]";

print;
$b = $_;
$b =~ tr/a-zA-Z0-9.,!?;//cd;
print;
print $b;

__END__


 
 


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

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