You can do the same as in the answer to your other question, but building a regex object using kWord.join('|').kWord[0] = 'int';kWord[1] = 'float';kWord[2] = 'char';kWord[3] = 'bool';kWord[4] = 'main';kWord[5] = 'void\\s+main';kWord[6] = 'int\\s+main';kWord[7] = 'cout';kWord[8] = 'cin';var r = '\\b(' + kWord.join('|') + ')\\b';var myRegex = new RegExp(r, 'g');str = str.replace(myRegex, ""); 这篇关于如何使用数组删除字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 07:33