3 Replies Latest reply on Feb 17, 2017 1:48 AM by SimonLinden

    can string.match() find more than one match?

    SimonLinden Level 1

      I don't seem to get the string.match() function right. What I want for it is to return an array with all the matches found but it only seems to return the first one. Is this how it's supposed to work and can anyone suggest another function or a workaround for me? I need to know if there is more than one occurrence of the pattern searched for.


      E.g. the code below I'd like to return an array of two matches:

      var keyword = "see";

      var str = "Let's see if you can see me";

      var match = str.match(new RegExp(keyword)); //match = see


      I'll be making tens of thousands of these calls for the project I'm working on so it's good if its fairly efficient. The only workaround I can think of is using findGrep() instead, but it seems a little over the top for this?