re = /(?<content>(?<type>.+?)\/(?<sub>.+?)(?:\+(?<suffix>.+?))?)(?:;.*?(?:q=(?<weight>[.\d]+))?.*?)?(?:,|$)/m
str = '*/*
text/html,application/json;q=0.9
application/json; charset=utf-8
application/json; xx=utf-8
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
application/javascript
application/x-www-form-urlencoded
application/ld+json
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.wordprocessingml.document
multipart/form-data
'
# 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