Logan Capaldo
7/21/2006 7:48:00 PM
On Jul 21, 2006, at 3:40 PM, Jim Cochrane wrote:
> On 2006-07-21, Theallnighter Theallnighter
> <theallnighter@gmail.com> 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'