package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?sm)(CREATE TABLE.*?;)`)
var str = `DROP TABLE IF EXISTS \`aes_interval\`;
CREATE TABLE \`aes_interval\` (
\`processcode\` bigint(20) NOT NULL,
\`overstaying\` int(11) NOT NULL,
\`floating\` int(11) NOT NULL,
PRIMARY KEY (\`processcode\`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci;
by running a RegEx that would select all in between (...) i will be able to get an output/substringed text like below:
CREATE TABLE \`aes_interval\` (
\`processcode\` bigint(20) NOT NULL,
\`overstaying\` int(11) NOT NULL,
\`floating\` int(11) NOT NULL,
PRIMARY KEY (\`processcode\`) USING BTREE
);`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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 Golang, please visit: https://golang.org/pkg/regexp/