Remove the flag /g.
The RegExp object is somehow reused. When a flag is present /g, the regex engine will start from the previous matching location until the entire line is destroyed.
1st call: Test
^
after 1st call: Test (found "Test")
^
2nd call: Test
^
after 2nd call Test (found nothing, reset)
^
BTW, \wequivalent [0-9a-zA-Z_]in Javascript. Therefore, the flag \d|and /iare redundant. And since you are not using a captured group, there is no need to store (…). It's enough:
var regexp_name = /^\w*$/;
source
share