正则匹配自定义 目前匹配了字母,数字,中文
function maxStr (str = '') {
str = str.split('').sort((a, b) => a.localeCompare(b)).join('')
let flag = false
let strNum = 0
let strArr = []
for (let index = str.length; index > 0; index--) {
let reg = new RegExp('([a-zA-Z0-9\\u4e00-\\u9fa5])\\1{' + (index - 1) + '}', 'g')
str.replace(reg, (content, $1) => {
flag = true
strNum = index
strArr.push($1)
})
if (flag) break
}
return `出现最多的字符有【${strArr.join()}】共${strNum}次`
}