【发布时间】:2018-12-08 02:44:41
【问题描述】:
过去,我有这个正则表达式:
\{(.*?)\}
并输入了这个字符串:
logs/{thing:hi}/{thing:hello}
然后我使用了以下内容:
console.log(string.split(regex).filter((_, i) => i % 2 === 1));
要得到这个结果:
thing:hi
thing:hello
出于不相关的设计原因,我将我的正则表达式更改为:
\{.*?\}
但是现在,当使用相同的测试字符串和分割命令时,它只返回这个:
/
我想要它返回这个:
{thing:hi}
{thing:hello}
如何修改拆分(或其他任何内容)来做到这一点?
【问题讨论】:
-
为什么不
match?s.match(/{.*?}/g)
标签: javascript regex typescript split match