Last active
December 19, 2015 03:48
-
-
Save Mon-Ouie/5892414 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
test_data = <<eof | |
do not match this line | |
match this as event 1 | |
and this a as 1 | |
and this b as 1 | |
do not match this line | |
match this as event 2 | |
and this x as 2 | |
and this y as 2 | |
and this z as 2 | |
but do not match this | |
eof | |
def next_match(data, i) | |
a = data.match(/^match.+$/, i) | |
return unless a # no more data | |
b = data.match(/^\S/, a.end(0)) | |
last = b ? b.begin(0) : data.length | |
lines = data[(a.end(0) + 1)...last].lines | |
puts "Match line: #{a}" | |
puts "Lines starting with a space: #{lines}" | |
# returns the next index | |
puts last | |
last | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment