Regular expression,

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'

···

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

You're almost there:

a[/(.*)_/, 1]

http://ruby-doc.org/core-2.0.0/String.html#method-i-5B-5D

···

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

hi,

oh I have made a small mistake, I have tried like a[/(.*)_/, \1]. Thank
you.

···

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

hi Robert Klemme

Another clever way, thank you.

···

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

irb(main):001:0> 'hi how are you_I am fine'.sub! /_.*/, ''
=> "hi how are you"

Kind regards

robert

···

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/