<script>
function findMaxStr(str){
//字符串转数组
let arr = str.split('');
//数组转字符串
str = arr.sort().join('');
let value = '';
let count = 0;
//定义规则
let ruler = /(\w)\1+/g;//匹配字符,且重复字符,重复次数至少一次
str.replace(ruler,function($0,$1){
//$0 代表匹配结果
//$1 代表匹配成功的第一个子项
if(count<$0.length){
count = $0.length;
value = $1;
}
})
console.log("出现最多的字符是:"+value+",出现的次数为:"+count);
}
let str = "ngsdaaaiiibbbb";
findMaxStr(str);
</script>
网友评论