知道java中怎么用正则表达式去掉sql代码段的注释吗?
比如
create teable testtable1as
(select * from tablename1
);
--sql2
create teable testtable2as
(select * from tablename2
);
/*sql3*/
create teable testtable3as
(select * from tablename3
);
要把这两种注释都去了,正则表达式如何写呀?
比如
create teable testtable1as
(select * from tablename1
);
--sql2
create teable testtable2as
(select * from tablename2
);
/*sql3*/
create teable testtable3as
(select * from tablename3
);
要把这两种注释都去了,正则表达式如何写呀?
怎样考虑换行回车?
String[] sa = new String[4];// 格式1
/**
* ABCDEFG
* ABCDEFAG
* DGDGDG
*/
sa[0] = "/**\r\n * ABCDEFG\r\n * ABCDEFAG\r\n * DGDGDG\r\n */"; // \r\n
sa[1] = "/**\n * ABCDEFG\n * ABCDEFAG\n * DGDGDG\n */"; // \n// 格式2
/* ABCDEFG
ABCDEFAG
DGDGDG */sa[2] = "/*ABCDEFG\r\nABCDEFAG\r\nDGDGDG*/"; // \r\n
sa[3] = "/*ABCDEFG\nABCDEFAG\nDGDGDG*/"; // \nfor (int i=0; i<sa.length; i++) {
System.out.println(
Pattern.matches(regex, sa[i]));
}
...
sa[4] = "/*ABCDEFGABCDEFAGDGDGDG*/";
...
请解释一下原因..
String regex = "[/*].*((\r)?+(\n)*(.)*)*[*/]";--〉String regex = "(/\*).*((\r)?+(\n)*(.)*)*(\*/)";