oxo oxo - 11 months ago 53
Ruby Question

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

Say I have a string:

Hey what's up @dude, @how's it going?

I'd like to remove all the characters before

Answer Source

or with the regex:

str = "Hey what's up @dude, @how's it going?"
str.gsub!(/.*?(?=@how)/im, "") #=> "@how's it going?"

you can read about lookaround at here