function count( str ){
var match = str.match(/(-+)/);
return match ? match[0].length : 0;
}
console.log( count("--qwerty") );
Или, если вы хотите передать начальный символ
function count( char, str ){
var newRE = new RegExp( "(" + char + "+)","" );
var match = str.match( newRE );
return match ? match[0].length : 0;
}
console.log( count("-", "--qwerty") );