package main import ( "fmt" "github.com/scott-x/gutils/fs" "regexp" ) func main() { c, _ := fs.ReadFile1("temp.sql") //remove comment start with # or -- re_comment1 := regexp.MustCompile(`(\s{0,}--.*)`) re_comment2 := regexp.MustCompile(`(\s{0,}#.*)`) re_comment3 := regexp.MustCompile(`(\s{0,}comment.*),`) re_comment4 := regexp.MustCompile(`(\s{0,}comment.*)`) c = re_comment1.ReplaceAllString(c, "") c = re_comment2.ReplaceAllString(c, "") c = re_comment3.ReplaceAllString(c, ",") c = re_comment4.ReplaceAllString(c, "") //replace create table => CREATE TABLE re_replace := regexp.MustCompile(`(create table)`) c = re_replace.ReplaceAllString(c, "CREATE TABLE") // fmt.Println(c) // get the table comment re := regexp.MustCompile(`CREATE TABLE(.*\n)(.*,\n)+(.*\n).*;`) arr := re.FindAllString(c, -1) fmt.Println(arr) fmt.Println(len(arr)) }