如何從 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.
自動化和腳本資料存取視窗回覆:如何從 Regex 傳回所有符合的結果?正規表示式符合()函數可能有效。
回覆:如何從 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 );回覆:如何從 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「自己的」模式匹配選項 腳本指南 > 資料類型 > 模式匹配
回覆:如何從 Regex 傳回所有符合的結果?謝謝!
回覆:如何從 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"};