Skip to content

Instantly share code, notes, and snippets.

@vargheseraphy
Last active August 29, 2015 14:15
Show Gist options
  • Save vargheseraphy/9b366c7d7787af1d32fc to your computer and use it in GitHub Desktop.
Save vargheseraphy/9b366c7d7787af1d32fc to your computer and use it in GitHub Desktop.
replace new line from matching word
irb1(main):029:0> "- dredtrnedtdj - uifsdkghdkjghjh ".split(/- /)
=> ["", "dredtrnedtdj ", "uifsdkghdkjghjh "]
irb1(main):031:0> "- dredtrnedtdj - fsjfsgdgdgdffff-gdfjdgjdgdg".split(/- /).compact.reject(&:empty?).each {|t| puts "#{t}"}
dredtrnedtdj
fsjfsgdgdgdffff-gdfjdgjdgdg
=> ["dredtrnedtdj ", "uifsdkghdkjghjh ", "fsjfsgdgdgdffff-gdfjdgjdgdg"]
irb1(main):032:0> "- dredtrnedtdj - fsjfsgdgdgdffff - gdfjdgjdgdg".split(/- /).compact.reject(&:empty?).each {|t| puts "#{t}"}
dredtrnedtdj
fsjfsgdgdgdffff
gdfjdgjdgdg
=> ["dredtrnedtdj ", "uifsdkghdkjghjh ", "fsjfsgdgdgdffff ", "gdfjdgjdgdg"]
irb1(main):033:0> x= "- dredtrnedtdj - uifsdkghdkjghjh - fsjfsgdgdgdffff - gdfjdgjdgdg".split(/- /)
=> ["", "dredtrnedtdj ", "uifsdkghdkjghjh ", "fsjfsgdgdgdffff ", "gdfjdgjdgdg"]
irb1(main):034:0> y= x.compact.reject(&:empty?)
=> ["dredtrnedtdj ", "uifsdkghdkjghjh ", "fsjfsgdgdgdffff ", "gdfjdgjdgdg"]
irb1(main):035:0> "- dredtrnedtdj - uifsdkghdkj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment