2021年3月6日星期六

How to find count matches in string with a regexp and variable, javascript

Hello I need to get the number of matches for each character in a string and I am trying to use "for" and RegEx but my code doesn't work because I don't know how to use variables in RegEx

let foo = (str) => {    for(let i=0; i< str.length; i++){    console.log((str.match(/{HERE MUST BE str[i]}/g) || []).length);    }  };    foo('Wabba');  
https://stackoverflow.com/questions/66512813/how-to-find-count-matches-in-string-with-a-regexp-and-variable-javascript March 07, 2021 at 11:04AM

没有评论:

发表评论