在尝试查找所有匹配项时,string.search()对我不起作用:
var test = "This is a sample text";
var result = test.search(/ /g);
// result = "4"
但它适用于string.matches()
var test = "This is a sample text";
var result = test.match(/ /g);
// result = " , , , "
理由是什么呢?不是提供了在string.