re = /\s*([JSESSIONID]+)\s*=\s*(?:"([^"])"|([^;"]*))\s*/
str = 'HTTP/1.1 302 Found
Date: Fri, 10 Jun 2016 21:44:38 GMT
Set-Cookie: JSESSIONID=1n9rk5co2o4xkpr327clod1pu;Path=/genesys;Expires=Sat, 11-Jun-2016 21:44:38 GMT;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://192.168.1.200:8010/genesys/admin/login.jsp#/
Content-Length: 0'
# 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