统计字符个数:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title></head><body><script>var count = 0;var stopposition = 0var item = "stop"var str = "start,stop,speed,start,stop,speed,start,stop,speed,start,stop,speed,"while( stopposition < str.length ){if( str.indexOf( item , stopposition) > 0 ){count ++stopposition = str.indexOf( item , stopposition)stopposition += item.length ;}else{stopposition += str.length}}console.log(str)console.log( '个数为', count );</script></body></html>
正则的基本表达: