oxo oxo - 1 year ago 83
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download