Espressione regolare per trovare e sostituire una stringa in una formulaCiao a tutti,
I try to replace one specific part As Constant( t Quantile( 1 - 0.1 / 2, in every selected column formula by Random t((.
Tuttavia, non riesco a gestire le espressioni regolari. Credo che il problema sia l'escape delle parentesi. Ho provato con \!\, ma ho fallito anche qui...
Qualcuno potrebbe eseguire il debug del mio codice qui sotto?
// 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) ) )
) );
);
Automazione e scriptingFinestreRe: Espressione regolare per trovare e sostituire una stringa in una formulaProbabilmente puoi usare Substitute o Substitute Into invece di Regex
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: Espressione regolare per trovare e sostituire una stringa in una formulasì, le espressioni regolari necessitano almeno della sequenza di escape delle parentesi del modello.