分别匹配元音字母
var reg = new Array(6);
reg[1] = new RegExp(/a/, 'ig');
reg[2] = new RegExp(/e/, 'ig');
reg[3] = new RegExp(/i/, 'ig');
reg[4] = new RegExp(/o/, 'ig');
reg[5] = new RegExp(/u/, 'ig');
for (var i = 1; i <= 5; i++) {
var matchCount = words.match(reg[i]);
if (matchCount)
score += (matchCount.length)*i;
}
alert("Score:"+score);
**统计字母、数字和其他字符 **
var regChar = new RegExp(/[a-z]/, 'g');
var regNum = new RegExp(/\d/, 'ig');
var regOther = new RegExp(/[^a-z0-9]/, 'ig');
网友评论