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'
on 2013-11-08 09:30
on 2013-11-08 09:46
You're almost there: a[/(.*)_/, 1] http://ruby-doc.org/core-2.0.0/String.html#method-i-5B-5D
on 2013-11-08 09:48
hi, oh I have made a small mistake, I have tried like a[/(.*)_/, \1]. Thank you.
on 2013-11-08 14:14
irb(main):001:0> 'hi how are you_I am fine'.sub! /_.*/, '' => "hi how are you" Kind regards robert
on 2013-11-08 14:16
hi Robert Klemme Another clever way, thank you.