我想扫描一个流并只检索那些包含关键字的行,这就是我到目前为止所得到的......
ERROR_WORDS = ['Error','Invalid','Out of Range']
error_stream = stderr.read
errors = nil
unless error_stream.nil?
errors = ERROR_WORDS.detect{ |e| error_stream.include? e }
假设error_stream
包含这个...
4/19/12 - 9:00am: Last check, status ok
4/19/12 - 9:15am: File # 456 received contained Error
4/19/12 - 9:30am: Last check, status ok
4/19/12 - 9:45am: File # 457 is has an Invalid timestamp
...我想扫描流并errors
仅返回具有 in 中的任何关键字的那些行(完整)ERROR_WORDS
,因此,在这种情况下,只有第 2 行和第 4 行包含错误词
我需要errors
,再想一想,它可能需要是一个数组,才能拥有......
4/19/12 - 9:15am: File # 456 received contained Error
4/19/12 - 9:45am: File # 457 is has an Invalid timestamp
我的代码返回这个...
Error
Invalid