Forum: Ruby regular expression,

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.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2013-11-08 09:30
a='hi how are you_I am fine"

now if write a[/(.*)/_] here it includes "_" symbol also with hi how are
you. I can use delete() function to delete "_" but I would like to
handle using regular expression alone. how would I write for that?

require output is,

'hi how are you'
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-11-08 09:46
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2013-11-08 09:48
hi,

oh I have made a small mistake, I have tried like a[/(.*)_/, \1]. Thank
you.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-08 14:14
(Received via mailing list)
irb(main):001:0> 'hi how are you_I am fine'.sub! /_.*/, ''
=> "hi how are you"

Kind regards

robert
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2013-11-08 14:16
hi Robert Klemme

Another clever way, thank you.
This topic is locked and can not be replied to.