如何在jquery中获取字符串中所有大写字符的位置?
假设
var str = "thisIsAString";
答案是 4,6,7(t 在索引 = 0 处)
最佳答案
遍历字母并将它们与正则表达式匹配。例如
var inputString = "What have YOU tried?";
var positions = [];
for(var i=0; i<inputString.length; i++){
if(inputString[i].match(/[A-Z]/) != null){
positions.push(i);
}
}
alert(positions);
关于javascript - 如何找到字符串中所有大写字符的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27152871/