Skip to content

Instantly share code, notes, and snippets.

@sj26
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sj26/d5a4be81bef1c98f249f to your computer and use it in GitHub Desktop.
Save sj26/d5a4be81bef1c98f249f to your computer and use it in GitHub Desktop.

@simpsora: any suggestions for a good way to parse multi-line messages in ruby? have command output which consists of blocks of 3 lines each, need to process each block together @sj26: maybe using scan and multiline regex?

$ ruby multiline.rb multiline.txt
["thing", "whatsit"]
["thang", "poppy"]
["thung", "scooby doo"]
["thong", "shaggy"]
ARGF.read.scan(/^Start: (.*)\nmiddle=(.*)\nEnd\./) do |match|
puts match.inspect
end
Start: thing
middle=whatsit
End.
Start: thang
middle=poppy
End.
Start: thung
middle=scooby doo
End.
Start: thong
middle=shaggy
End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment