467,179 Members | 1,271 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

how to remove numbers from a string?

How to remove all the numbers from a string like this?

$string="dfjgkk4kgl56lfka88lf"

Thanks a lot!
Sep 10 '08 #1
  • viewed: 20031
Share:
4 Replies
numberwhun
Expert Mod 2GB
Please know that I am not normally one for just giving up code. Its not condusive to your learning. But, this is one of those times where I am inclined to do so.

You would do something like the following which is a substitution, replacing all digits with nothing.

Expand|Select|Wrap|Line Numbers
  1. $string =~ s/\d//g;
  2.  
Untested, but I think it should work.

Regards,

Jeff
Sep 10 '08 #2
Please know that I am not normally one for just giving up code. Its not condusive to your learning. But, this is one of those times where I am inclined to do so.

You would do something like the following which is a substitution, replacing all digits with nothing.

Expand|Select|Wrap|Line Numbers
  1. $string =~ s/\d//g;
  2.  
Untested, but I think it should work.

Regards,

Jeff

Thanks for your help! You're right, I will try to think more before my asking.
Thank you again!
Sep 11 '08 #3
KevinADC
Expert 2GB
probably a bit more efficient:

Expand|Select|Wrap|Line Numbers
  1. $string =~ tr/0-9//cd;
c = compliment of search pattern
d = delete

tr/// is very good for these simpler type of task requiring a regexp. s/// is good for the more complex stuff.
Sep 11 '08 #4
probably a bit more efficient:

Expand|Select|Wrap|Line Numbers
  1. $string =~ tr/0-9//cd;
c = compliment of search pattern
d = delete

tr/// is very good for these simpler type of task requiring a regexp. s/// is good for the more complex stuff.
That's helpful! Thank you!
Sep 11 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Matthias S. | last post: by
36 posts views Thread by laredotornado@zipmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.