[英]Find and substitute semicolons which are not enclosed in quotes
I have a multiline SQL script in which I need to replace the ";" 我有一个多行SQL脚本,需要在其中替换“;” characters which are at the end of the statements with the sequence "\\nGO", leaving the ";" 语句末尾的字符,其序列为“ \\ nGO”,保留“;” which are not at the end of the statements (the ones which are included in a string). 不在语句末尾的内容(包含在字符串中的内容)。
This is an example text 这是一个示例文本
Insert into TABLE1 (A, B) values ('a','b');
Insert into TABLE2 (COMMAND) values ('/* Script generated at 20.04.2006 12:38:44 */
/* error_permissible = 955*/
Create Table map_encodekey
( privatekey VARCHAR2(30) NOT NULL
);
/* error_permissible = 2260*/
Alter Table map_encodekey
Add Constraint map_encodekey_pk
Primary Key
(privatekey);
');
So I need to replace only the two semicolons at the end of the two INSERT
statements, leaving the ones in the string (wchich is a SQL command, but this doesn't matter). 因此,我只需要在两个INSERT
语句的末尾替换两个分号,就将它们保留在字符串中(wchich是一个SQL命令,但这并不重要)。
I tried this, but it finds me all the ";" 我试过了,但是找到了所有的“;”
/(?<!['])(?<![;])[;](?![;])(?!['])/g
What do you think the regex should look like? 您认为正则表达式应该是什么样?
;(?=(?:[^']*'[^']*')*[^']*$)
You can use this and replace by \\nGO
.See demo. 您可以使用它并用\\nGO
代替\\nGO
演示。
https://regex101.com/r/cJ6zQ3/35 https://regex101.com/r/cJ6zQ3/35
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.