I know this is a more Ruby thing, but I want to strip out all non-word (\W) characters from a string. Is there a regexp way to do this? Right now, I have: params[:object][:item].sub!(/(\W)*/,'''') but that only removes the first instance, not all non-word chars. Thanks, - Nic.
I think you just want to call gsub instead of sub... b Nic Werner wrote:> I know this is a more Ruby thing, but I want to strip out all non-word > (\W) characters from a string. > > Is there a regexp way to do this? Right now, I have: > > params[:object][:item].sub!(/(\W)*/,'''') > > but that only removes the first instance, not all non-word chars. > > Thanks, > > - Nic. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Of course, thanks! On 2/22/06, Ben Munat <bent@munat.com> wrote:> I think you just want to call gsub instead of sub... > > b > > Nic Werner wrote: > > I know this is a more Ruby thing, but I want to strip out all non-word > > (\W) characters from a string. > > > > Is there a regexp way to do this? Right now, I have: > > > > params[:object][:item].sub!(/(\W)*/,'''') > > > > but that only removes the first instance, not all non-word chars. > > > > Thanks, > > > > - Nic. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Nic