【发布时间】:2020-01-30 06:57:09
【问题描述】:
我正在使用这两行脚本来更新迁移脚本 - https://github.com/dotnet/efcore/issues/12911#issuecomment-505596919。
$sql = get-content .\migration.sql -raw
[regex]::replace($sql, "BEGIN\s+(CREATE (?:VIEW|TRIGGER).+?)END", "BEGIN`nEXEC('`$1');`nEND", "ignorecase,singleline") > migration.sql
问题是它不能替换单引号,所以如果我有这样的查询:
BEGIN
CREATE VIEW someview AS
select lastname + ', ' + firstname from sometable
END;
我结束了
BEGIN
EXEC('CREATE VIEW someview AS select lastname + ', ' + firstname from sometable');
END;
那是行不通的。也许是因为这是一天的结束,我感觉很紧张,但我需要做些什么来替换它捕获的引号?我知道如何在 C# 中做到这一点,但我是 Powershell 新手。
【问题讨论】:
-
正则表达式不匹配,因为存在
select lastname而不是CREATE VIEW或CREATE TRIGGER。您要添加到正则表达式的规则是什么? -
我搞砸了我的复制/粘贴。立即修复。
标签: regex powershell