Regex から一致したすべての結果を返すにはどうすればよいでしょうか?正規表現検索からすべての結果を返すにはどうすればよいですか?
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.
自動化とスクリプトデータアクセスウィンドウズRe: Regex から一致した結果をすべて返すにはどうすればいいですか?正規表現マッチ()関数が機能する可能性があります。
Re: Regex から一致した結果をすべて返すにはどうすればいいですか?ご意見ありがとうございます。Regex Match() はまだすべての結果を返しません。少なくとも私が書いた方法では返しません。
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 );Re: Regex から一致した結果をすべて返すにはどうすればいいですか?私の知る限り、Regex(またはRegex Match)を使用するだけでは現時点では実行できません。Regex Match()にフラグを追加して、パターンの重複しない出現をすべて見つけます。Pythonを使用することもできますが、ループ付きのJSLを使用することもできます。
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^"};
または、JMP 独自のパターン マッチングという、より複雑なオプションもあります。スクリプト ガイド > データの種類 > パターン マッチング
Re: Regex から一致した結果をすべて返すにはどうすればいいですか?ありがとう!
Re: Regex から一致した結果をすべて返すにはどうすればいいですか?JMP の Word() 関数と Jarmo の方法論を組み合わせて使用することでも問題を解決できます。
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"};