我有一个声明:
INSERT INTO table_name (c1,c2,c3) VALUES ('',N'user','','1970-01-01 00:00:00.0')
我想创建一个正则表达式,运行它将给我以下结果:
table_name
c1,c2,c3
'',N'user','','1970-01-01 00:00:00.0'
基于this的问题和答案,我创建了以下内容:
final String regex = "((?<=(INSERT\\sINTO\\s))[\\w\\d_]+(?=\\s+))|((?<=\\()([\\w\\d_,]*|[N?'?.*\\s?.*'?,]*)+(?=\\)))";
但是,我的回答仅仅是:
table_name
c1,c2,c3
'',N'user',''
能否请您帮我,告诉我我做错了什么?
我要测试的代码:
final String regex = "((?<=(INSERT\\sINTO\\s))[\\w\\d_]+(?=\\s+))|((?<=\\()([\\w\\d_,]*|[N?'?.*\\s?.*'?,]*)+(?=\\)))";
String test = "INSERT INTO table_name (c1,c2,c3) VALUES ('',N'user','','1970-01-01 00:00:00.0')";
Pattern re = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = re.matcher(test);
while (m.find())
{
System.out.println(m.group(0));
}
答案 0 :(得分:0)
找到了! :)
((?<=(INSERT\\sINTO\\s))[\\w\\d_]+(?=\\s+))|((?<=\\()([\\w?\\d?_,]*|[(?:^|\\s)'([^']*?)'(?:$|\\s),]*)+(?=\\)))