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.
Nic W. (Guest)
on 2006-02-23 08: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.
Ben M. (Guest)
on 2006-02-23 08:55
(Received via mailing list)
I think you just want to call gsub instead of sub...

b
Nic W. (Guest)
on 2006-02-23 09:01
(Received via mailing list)
Of course, thanks!


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


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