From: Jim Cochrane Date: 2006-07-22T04:40:05+09:00 Subject: Re: Newbie Question: delete all non alphanumeric characters On 2006-07-21, Theallnighter Theallnighter wrote: > Hi all, > how can i delete all non alphanumeric characters in a string ? thanks > I've also just started to learn Ruby, so thought I'd reply for the practice - Here's one solution: ------------------------------------------------------------------------ #!/usr/bin/ruby x = "There are 2007 beans and 15234 grains of rice in this bag." puts x x.gsub!(/\W/, '') puts x ------------------------------------------------------------------------ output: There are 2007 beans and 15234 grains of rice in this bag. Thereare2007beansand15234grainsofriceinthisbag --