re = /CREATE TABLE\s+\'([^\']+)[\s\S]+PRIMARY KEY\(([^,]+),([^\)]+)\)/
str = 'CREATE TABLE \'dhcpr_dhcprelayinterface\' (
\'vrId\' integer default 0,
\'ifName\' string ,
PRIMARY KEY(ifName,vrId),
FOREIGN KEY (vrId) REFERENCES \'vr_vr\'(vrId) ON DELETE CASCADE ON UPDATE CASCADE);'
# 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