如何使用唯一的子串JavaScript拆分字符串

时间:2014-09-03 09:42:51

标签: javascript string split

如何将"somestring\correct{s}\wrong{g}somestring\correct{w}somestring"等JavaScript字符串拆分为["somestring", "\correct{s}", "\wrong{g}", "somestring", "\correct{w}", "somestring"]

等数组

1 个答案:

答案 0 :(得分:0)

尝试.match

var arr = str.match(/\\?[a-z]+(?:\{[a-z]\})?/g)

应该工作!

console screenshot