【发布时间】:2012-12-03 10:33:30
【问题描述】:
这存在吗?
我需要解析如下字符串:
the dog from the tree
得到类似的东西
[[null, "the dog"], ["from", "the tree"]]
我可以在 Ruby 中使用一个 RegExp 和 String#scan。
JavaScript 的 String#match 无法处理这个问题,因为它只返回匹配的正则表达式而不是捕获组,所以它返回类似
["the dog", "from the tree"]
因为我在我的 Ruby 应用程序中多次使用String#scan,所以如果有一种快速的方法可以在我的 JavaScript 端口中复制这种行为,那就太好了。
编辑:这是我正在使用的正则表达式:http://pastebin.com/bncXtgYA
【问题讨论】:
标签: javascript ruby regex