Ruby grep with line number
Enumerable#grep doesn't let you do that, at least by default. Instead, I came up with:
text = 'now is the timefor all good mento come to the aidof their country'regex = /aid/hits = text.lines.with_index(1).inject([]) { |m,i| m << i if (i[0][regex]); m }hits # => [["to come to the aid\n", 3]]