Come restituire tutti i risultati corrispondenti da Regex?Come posso ottenere tutti i risultati di una ricerca Regex?
Sto utilizzando JMP 18.1.2.
Names Default To Here( 1 );
string = "I am looking for ^this^, ^that^, and sometimes ^those^.";
result = Regex( string, "\^([^\n]*?)\^" ); // Only returns first match.
Automazione e scriptingAccesso ai datiFinestreR: Come restituire tutti i risultati corrispondenti da Regex?La funzione Corrispondenza Regex() potrebbe funzionare.
R: Come restituire tutti i risultati corrispondenti da Regex?Grazie per il contributo. Regex Match() non restituisce ancora tutti i risultati. Almeno non nel modo in cui l'ho scritto.
Names Default To Here( 1 );
string = "I am looking for ^this^, ^that^, and sometimes ^those^.";
result = Regex( string, "\^([^\n]*?)\^" ); // Returns "^this^".
Show( result );
results = Regex Match( string, "\^([^\n]*?)\^" ); // Returns {"^this^", "this"}.
Show( results );R: Come restituire tutti i risultati corrispondenti da Regex?Per quanto ne so, al momento non è possibile farlo usando solo Regex (o Regex Match), Aggiungi flag a Regex Match() per trovare tutte le occorrenze non sovrapposte di pattern . Puoi usare Python ma puoi anche usare JSL con un loop
Names Default To Here(1);
string = "I am looking for ^this^, ^that^, and sometimes ^those^.";
result = Regex(string, "\^([^\n]*?)\^"); // Only returns first match.
matches = {};
While(!Is Missing(result = Regex(string, "\^([^\n]*?)\^")),
Substitute Into(string, result, "");
Insert Into(matches, result);
);
show(matches); // matches = {"^this^", "^that^", "^those^"};
o l'opzione molto più complicata del pattern matching "proprio" di JMP Guida allo scripting > Tipi di dati > Pattern matching
R: Come restituire tutti i risultati corrispondenti da Regex?Grazie!
R: Come restituire tutti i risultati corrispondenti da Regex?Anche utilizzando la funzione Word() di JMP insieme alla metodologia di Jarmo è possibile risolvere il problema.
Names Default To Here(1);
string = "I am looking for ^this^, ^that^, and sometimes ^those^.";
result = Regex(string, "\^([^\n]*?)\^"); // Only returns first match.
matches = {};
While(!Is Missing(result = word(2,string, "^")),
Substitute Into(string, "^"||result||"^", "");
Insert Into(matches, result);
);
show(matches); // matches = {"^this^", "^that^", "^those^"};
matches = {"this", "that", "those"};