re = /create\s+table\s*`\w*`\s*\(\n\s*`([\w\-_]*)`\s*([\w]*).*(auto_increment)([\n\s\w()',`]*)(primary key)\s*\(`([\w\-_]*)`\).*\n.*engine\s*=\s*(InnoDB).*charset\s*=\s*([\w\-]*);/i
str = 'CREATE TABLE `column_statiskey_map` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Platform` varchar(255) NOT NULL,
`ColumnName` varchar(255) NOT NULL DEFAULT \'\',
`Statiskey` varchar(255) NOT NULL DEFAULT \'\',
`Status` int(11) NOT NULL DEFAULT \'0\',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;'
# 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