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’

hi,

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

irb(main):001:0> ‘hi how are you_I am fine’.sub! /_.*/, ‘’
=> “hi how are you”

Kind regards

robert

hi Robert K.

Another clever way, thank you.

You’re almost there:

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs