I'm looking for an equivalent to std.strReplace(str, from, to)
to replace parts of a string in Jsonnet. I would need from
to be more like a "pattern", something like s/key="[^"]*"/key="myNewValue"/g
, so actually what I'm looking for would be a regex-search-and-replace.
Edit: Ok this could possibly help me with my specific issue:
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, '"')
])
);
However the "set a new value for previously defined local variable" (replaceNext = true;
) won't work.
Not a binary operator: =
Any ideas how to do it?