How do I remove all characters in a string until a substring is matched, in Ruby?

后端 未结 7 910
时光说笑
时光说笑 2021-02-13 16:48

Say I have a string: Hey what\'s up @dude, @how\'s it going?

I\'d like to remove all the characters before@how\'s.

相关标签:
7条回答
  • 2021-02-13 17:46

    An easy way to get only the part you are interested in.

    >> s="Hey what's up @dude, @how's it going?"
    => "Hey what's up @dude, @how's it going?"
    >> s[/@how.*$/i]
    => "@how's it going?"
    

    If you really need to change the string object, you could always do s=s[...].

    0 讨论(0)
提交回复
热议问题