Skip to content

Instantly share code, notes, and snippets.

@oleander
Created September 1, 2015 21:06
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 oleander/17f6be2c2db939a859f1 to your computer and use it in GitHub Desktop.
Save oleander/17f6be2c2db939a859f1 to your computer and use it in GitHub Desktop.
require "pp"
# data = File.read("exam.txt")
require "strscan"
# data = "123. This is a question A Option One B Option two C Danke D Nope"
data = "This is stuff 1. Number one 2. Number two 5. End of line"
scanner = StringScanner.new(data)
while option = scanner.scan(/ (\d+)\. /m)
puts "Option: #{scanner.scan_until(/(?= (\d+)\. )/m) || scanner.rest}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment