re = /<(\S+)>\s*<(\S+)>\s*(?:"(.+)"|<(\S+)>).*./
str = '# started 2015-11-29T18:23:17Z
<http://dbpedia.org/resource/Bobcat_Company> <http://dbpedia.org/property/type> <http://dbpedia.org/resource/Subsidiary> .
<http://dbpedia.org/resource/Bobcat_Company> <http://dbpedia.org/property/website> <http://www.bobcat.com> .
<http://dbpedia.org/resource/Albedo> <http://dbpedia.org/property/colwidth> "30"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://dbpedia.org/resource/Anarchism> <http://dbpedia.org/property/voy> "no"@en .
<http://dbpedia.org/resource/Anarchism> <http://dbpedia.org/property/n> "no"@en .
<http://dbpedia.org/resource/Anarchism> <http://dbpedia.org/property/v> "no"@en .
<http://dbpedia.org/resource/Knight_Transportation> <http://dbpedia.org/property/keyPeople> "Kevin Knight"@en .
<http://dbpedia.org/resource/Knight_Transportation> <http://dbpedia.org/property/keyPeople> "Keith Knight"@en .
<http://dbpedia.org/resource/Knight_Transportation> <http://dbpedia.org/property/numEmployees> "4400"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://dbpedia.org/resource/Knight_Transportation> <http://dbpedia.org/property/industry> "motor transportation-trucking"@en .
<http://dbpedia.org/resource/Knight_Transportation> <http://dbpedia.org/property/products> "truckload shipping"@en .
'
# Print the match result
str.match(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