regex question

0 views
Skip to first unread message

Sam Ginko

unread,
Jun 25, 2008, 6:14:06 PM6/25/08
to rubyonra...@googlegroups.com
I'm trying to replace all characters that are not letters numbers and
white spaces in a string. I'm getting the characters eliminated in this
case a comma but the white space is eliminated to. How do I get around
that?


string = 'john, tony'
newTerms = string.gsub(/\W/, "")


thanks
--
Posted via http://www.ruby-forum.com/.

Philip Hallstrom

unread,
Jun 25, 2008, 6:39:00 PM6/25/08
to rubyonra...@googlegroups.com

On Jun 25, 2008, at 3:14 PM, Sam Ginko wrote:

>
> I'm trying to replace all characters that are not letters numbers and
> white spaces in a string. I'm getting the characters eliminated in
> this
> case a comma but the white space is eliminated to. How do I get around
> that?
>
>
> string = 'john, tony'
> newTerms = string.gsub(/\W/, "")

> newTerms = string.gsub(/[^\w\s]/, "")
=> "john tony"

is one way...

Sam Ginko

unread,
Jun 25, 2008, 7:03:35 PM6/25/08
to rubyonra...@googlegroups.com
Philip Hallstrom wrote:

>>
>> string = 'john, tony'
>> newTerms = string.gsub(/\W/, "")
>
> > newTerms = string.gsub(/[^\w\s]/, "")
> => "john tony"
>
> is one way...

thanks a million

Reply all
Reply to author
Forward
0 new messages