尝试在一个新匹配中使用匹配函数的结果时出现问题。JavaScript中的重复匹配
这是代码:
<html>
<body>
<script type="text/javascript">
p="somelongtextmelongtextmelongtextmelongtext";
f1 = p.match(/some/g);
document.write(f1);
f2 = f1.match(/om/g);
document.write(f2);
</script>
</body>
</html>
输出是单词“一些”时,它必须是“嗡”。我不明白这种行为,我需要在更复杂的情况下输出f1。
在此先感谢。
是的。这就是代码。我很困惑,因为我总是看到结果是一个字符串,因为格式是match1,match2等......和document.write(f1);显示有效的输出而不使用数组格式。非常感谢你。 – Memochipan
使用控制台比使用document.write测试东西要好。它会显示一个数组,而不是数组的toString()等价物。 – epascarello
编辑我的答案使用'console.log' per @ epascarello的评论 – digitalbath