【发布时间】:2021-11-05 11:58:54
【问题描述】:
我正在寻找与 std.strReplace(str, from, to) 等效的方法来替换 Jsonnet 中的部分字符串。我需要from 更像一个“模式”,类似于s/key="[^"]*"/key="myNewValue"/g,所以实际上我正在寻找的是一个正则表达式搜索和替换。
编辑: 好的,这可能会帮助我解决我的具体问题:
local replaceKey(string) = (
local replaceNext = false;
std.join('"', [
if std.endsWith(x, "key=") then
replaceNext = true;
x
else if replaceNext then
replaceNext = false;
"myNewValue"
else
x
for x in std.split(string, '"')
])
);
但是“为先前定义的局部变量设置一个新值”(replaceNext = true;)将不起作用。
Not a binary operator: =
有什么办法吗?
【问题讨论】:
标签: jsonnet