-
-
Save oleander/17f6be2c2db939a859f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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