Hi,

You can use gsub(/[^0-9a-zA-Z,]/, '') to replace only non numbers, alphabets
and ,

Regards,
NAYAK

On Mon, Dec 22, 2008 at 9:53 PM, Michael Libby <[email protected]>wrote:

>
> On Mon, Dec 22, 2008 at 10:09 AM, elioncho <[email protected]> wrote:
> >
> > Hello,
> >
> > I am trying to apply a gsub! to a string. I want to know how to make
> > the pattern evaluate that everything that IS NOT numbers, letters or
> > commas should be replaced with ""(nil). Any ideas in how to do this
> > pattern?
>
> irb(main):009:0> "123***,ABC,$$%abc,----+X+----".gsub(/[^\w,]/, '')
> => "123,ABC,abc,X"
>
> Build a character class with []
> Then choose \w and , as characters in the class that you want
>  (although note that \w includes all alphanumerics and _)
> Then negate them both with ^ at the start of the character class
>
> Much more information about Regexp in Ruby can be found here:
>
> http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html#S4
>
> -Michael
>
> --
> Michael C. Libby
> www.mikelibby.com
>
> >
>

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