I try to find sql script in a file to split in nodejs. Before split to text I add like -split- seperator with regex replace to begining of the sql script as the below:
SQL file:
/* this is a comment for create table */
--this is another comment for create table
create table test1 (comment varchar);
create temporary table test2 (comment varchar);
insert into text1 values('this is a comment for create table ')
Regex replace operation:
sqlText
.replace(/\s+create(\s+|global\s+|temporary\s+)table\s+/gi, `-split- CREATE $1 TABLE `)
Expected output:
/* this is a comment for create table */
--this is another comment for create table
-split- CREATE TABLE test1 (comment varchar);
-split- CREATE temporary TABLE test2 (comment varchar);
insert into text1 values('this is a comment for create table ')
But i get:
/* this is a comment for -split- CREATE TABLE */
--this is another comment for -split- CREATE TABLE
-split- CREATE TABLE test1 (comment varchar);
-split- CREATE temporary TABLE test2 (comment varchar);
insert into text1 values('this is a comment for -split- CREATE TABLE ')
How can I exclude the query sentences in the comment line and quotes?