Le 07/04/2010 11:44, Hemant Bhargava a écrit :
> Hello champs,
>
> I am having an string and i want all extra characters to be removed from
> that string except + and .
> How to write a regular expression for it.. Currently i am trying it like
> this as word.sub(/[_-\:\\\/]/, "").. But its not working..
>
> I can do it like this as well:- word.sub(/[\W]/, "") but this will
> replace all characters even also + and .
>   
This seems to be what you need :

str = "ABCD EF + (GH_IJ).klm _ ^^z"
str.gsub(/[^\w\+\.]|\_/i, '')
=> "ABCDEF+GHIJ.klmz"

-- 
Aurélien AMILIN

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to