但不是空字符串?
// loop through space separated "tokens" in a string
// will loop through "" - needs update
$P.eachString = function (str, func, con) {
var regexp = /^|\s+/;
if (regexp.test(str)) {
// ... stuff
}
};
上面的代码将匹配“”空字符串。我想与
匹配情形1
some_string
情形2
some_string1 some_string2
情形3
some_string1 some_string2 some_string_3
等
答案 0 :(得分:0)
只需使用String.split
并迭代返回的array
:
通过将字符串分隔为子字符串,将String对象拆分为字符串数组。
如果省略
separator
,则数组包含一个由整个字符串组成的元素。