我有以下代码:分割字符串的特定字符
var string = "word1;word2;word3,word4,word5,word6.word7";
function ends_with(string, character) {
var regexp = new RegExp('\\w+' + character, 'g');
var matches = string.match(regexp);
var replacer = new RegExp(character + '$');
return matches.map(function(ee) {
return ee.replace(replacer, '');
});
}
// ends_with(string, ';') => ["word1", "word2"]
该函数没有考虑空白。例如,如果输入
ends_with('Jonas Sand,', ',')
的输出将是Sand。需要关于使用带有空格的单词进行功能工作的帮助。
请把你的代码放在代码块 - CTRL + K :) – 2009-12-10 14:16:43