Forum: Ruby regular expression,

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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.