'1 and 1'.split(/\s+(and|or)\s+/i)结果是 ["1", "and", "1"]为什么不是 ["1", "1"]
1 回答

FFIVE
TA贡献1797条经验 获得超6个赞
因为有正则中用括号将and|or
包括起来了,相当于是捕获了,然后其捕获结果会返回给split
'1 and 1'.split(/\s+(?:and|or)\s+/i)
这样就不会捕获了。
添加回答
举报
0/150
提交
取消