1You could remove any other character in the string and check the length:
2
3str.replace(/[^aA]/g, "").length
4Here it is counted how many as are in str. The RegExp is described below:
5
6[ // Start Character Group
7^ // Not operator in character group
8a // The character "a"
9] // End character group
10
11//The g (global) in the regular expression tells the program to search
12//the whole string rather than just finding the first occurrence.