From: Logan Capaldo Date: 2006-07-22T04:48:24+09:00 Subject: Re: Newbie Question: delete all non alphanumeric characters On Jul 21, 2006, at 3:40 PM, Jim Cochrane wrote: > 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 > > -- > > Well the only "problem" with that is x = '\w includes_under_scores_too'