Bulletproof getCountOfAllMatches against non-global regex input
FREEBIE
This commit is contained in:
parent
423a0fef67
commit
0496518af4
2 changed files with 16 additions and 0 deletions
|
@ -21,6 +21,10 @@
|
|||
var match = regex.exec(str);
|
||||
var count = 0;
|
||||
|
||||
if (!regex.global) {
|
||||
return match ? 1 : 0;
|
||||
}
|
||||
|
||||
while (match) {
|
||||
count += 1;
|
||||
match = regex.exec(str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue