废话不多说了,直接给大家贴代码了,具体代码如下所示:
function maxLenStr(str){ var len = 0, max_len = 0; var reg = new RegExp("(.)1{1,}","g"); var res = reg.exec(str); while(res != null){ len = res[0].length; if(max_len < len){ max_len = len; } res = reg.exec(str) } return max_len; }
js使用正则查找子串
var str = '#param1#abcdef#param2#hjklllj#param3#7878' var count = str.match(/paramd*/g) console.log(count) // ["param1", "param2", "param3"]