正则表达式匹配,需要注意的是string.match()在无匹配结果是返回null,反之返回结果数组。 const readline = require('readline'); const getCharacterCountInString = (source, target) => { const targetRegExp = new RegExp(target, 'ig'); const matchs = source.match(targetRegExp); return matchs === null ? 0 : matchs.length; }; const ...