如何从 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"};