Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Last active December 19, 2015 03:48
Show Gist options
  • Save Mon-Ouie/5892414 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/5892414 to your computer and use it in GitHub Desktop.
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