数式内の文字列を検索して置換する正規表現やあみんな、
I try to replace one specific part As Constant( t Quantile( 1 - 0.1 / 2, in every selected column formula by Random t((.
しかし、正規表現の部分で失敗しました。括弧のエスケープが原因だと思います。\!\ を試してみましたが、ここでも失敗しました…
誰か以下のコードをデバッグしてもらえませんか?
// Select some columns
dt = currentdatatable();
dt << Get Selected Columns;
//'fix' each selected column formula by manipulating the formula as a string
for each( {col, c}, dt << Get Column References( dt << Get Selected Columns ),
newf = regex(
char(col << Get Formula),
"As Constant( t Quantile( 1 - 0.1 / 2, ",
"Random t((",
GLOBALREPLACE
);
//show(Parse(newf));
Eval( Eval Expr(
col << Set Formula( Expr( Parse(newf) ) )
) );
);
自動化とスクリプトウィンドウズRe: 数式内の文字列を検索して置換するための正規表現おそらく、Regexの代わりにSubstituteまたはSubstitute Intoを使用できるでしょう。
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
new_col = dt << new column("F", Numeric, Continuous, Formula(
As Constant(t Quantile(1 - 0.1 / 2, 1, 0))
));
f_expr = new_col << Get Formula;
f_str = Char(Name Expr(f_expr));
Substitute Into(f_str, "As Constant(t Quantile(1 - 0.1 / 2, ", "Random t((",);
Substitute Into(f_str, "((", "(", "))", ")");
new_col << Set Formula(Eval(Parse(f_str)));
Re: 数式内の文字列を検索して置換するための正規表現はい、正規表現では少なくともパターンの括弧をエスケープする必要があります。