469,328 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

how to remove numbers from a string?

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

$string="dfjgkk4kgl56lfka88lf"

Thanks a lot!
Sep 10 '08 #1
4 20535
numberwhun
3,503 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
anklos
30
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
4,059 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
anklos
30
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

3 posts views Thread by soni29 | last post: by
6 posts views Thread by Matthias S. | last post: by
36 posts views Thread by laredotornado | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.