re = /^\s*[0-9 |]*\s*#[ \t]*include\s*[<"](\S+)[">]/m
str = '... fatal error: Foobar.h: No such file or directory
#include <Foobar.h>
test.c:2:10: fatal error: \'file.h\' file not found
2 | #include <file.h>
| ^~~~~~~~
1 error generated.
... fatal error: Foobar.h: No such file or directory
2 | #include <Foobar.h>
... fatal error: Foobar.h: No such file or directory
2 | #include <Foobar.h>
test.c:3:4: error: expected identifier or \'(\'
3 | an "unrelated" error
| ^
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html