Solution for Rosetta Code: Count occurrences of a substring

What is your hint or solution suggestion?
The best solution is to use the str.match(new Regexp(subStr...)) method, which will return a list of all the matches. Also, the symbol * needs to be replaced with \\* which indicates a transition point between regular and italic fonts.

Solution 1
function countSubstring(main_str, sub_str){
    var subStr = sub_str.replace(/[*]/, '\\*');
    return (main_str.match(new RegExp(subStr, 'gi'))).length;

Challenge: Count occurrences of a substring

Link to the challenge: