Forum: Ruby on Rails Stripping out non-word characters?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B0e227ae419295321ca2aff4c27ad99d?d=identicon&s=25 Nic Werner (Guest)
on 2006-02-23 07:40
(Received via mailing list)
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.
4005a47a8f2ceee49670b920593c1d52?d=identicon&s=25 Ben Munat (Guest)
on 2006-02-23 07:55
(Received via mailing list)
I think you just want to call gsub instead of sub...

b
B0e227ae419295321ca2aff4c27ad99d?d=identicon&s=25 Nic Werner (Guest)
on 2006-02-23 08:01
(Received via mailing list)
Of course, thanks!


On 2/22/06, Ben Munat <bent@munat.com> wrote:
> > params[:object][:item].sub!(/(\W)*/,'')
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
- Nic
This topic is locked and can not be replied to.