在 Javascript 中使用内部和外部分隔符分割字符串
在我的 Javascript 代码中,我有一个像这样的字符串:
"1943[15]43[67]12[32]"
我想返回一个像这样的数组:
["1","9","4","3","15","4","3","67","1", 2","32"]
也就是说,我希望它分隔每个字符,除了括号内的数字,我想将其保留为一个元素。
有没有一种优雅的方法来做到这一点?
In my Javascript code, I have a string that is something like this:
"1943[15]43[67]12[32]"
I want to return an array like this:
["1","9","4","3","15","4","3","67","1", 2","32"]
That is, I want it to separate every character, except the numbers inside the brackets, which I want to preserve as one element.
Is there an elegant way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jsFiddle。
jsFiddle.