admin管理员组文章数量:1296910
This is what regex should find {
anything in it
}
, and then I want to count the number of results what the regex found.
So I have a string like this:
{example1}{example2}{example3}
in this case the count number is 3
This is what regex should find {
anything in it
}
, and then I want to count the number of results what the regex found.
So I have a string like this:
{example1}{example2}{example3}
in this case the count number is 3
1 Answer
Reset to default 11you need the global regex flag (g) to match all occurrences and then simply get the length of the result. the ? makes the .* ungreedy, otherwise it would only once fit the first and the last bracket as regexps are greedy by default.
var source = "{example1}{example2}{example3}";
var count = source.match(/\{.*?\}/g).length;
本文标签: JAVASCRIPT Count the number of REGEX resultsStack Overflow
版权声明:本文标题:JAVASCRIPT: Count the number of REGEX results - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741640109a2389866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论