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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and 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:


but that only removes the first instance, not all non-word chars.


 - 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...

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

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