javascript - How to count string occurrence in string? -


How often can I calculate a particular string in another string? For example, I'm trying to do this in JavaScript:

  var temp = "This is a string."; Warning (temp.count ("is")); // Regular in Output '2'  

g The expression (less for global ), instead of searching only the first event, searches the whole string:

  Var temp = "This is a string."; Var calculation = (temp.match (/ is / g) || []) Length; Console.log (count);  

This match is is twice and, if there are no matches, then this 0 returns.

  var temp1 =" Hello World! "; Var count1 = (temp1.match (/ is / g) || []) Length; Console.log (count1);  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -