Tell us what’s happening:
Describe your issue in detail here.
Your code so far
let username = "Oceans11";
let userCheck = /^[a-z][a-z]+\d*$|^[a-z][0-9][0-9]+/ig; // Change this line
let result = userCheck.test(username);
let resultVis = username.match(userCheck);
console.log(resultVis);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.
I’m not the OP, but since you brought that up… I just read that MDN doc out of curiosity. Good info to know about how global g affects test().
Since lastIndex is writable (as it must be, or it couldn’t be increased) how would one reset lastIndex manually, or in code if test() didn’t get a match (returned false)? or can you? or would you even want to? or is that just a side-effect of using g with test() that you have to live with?
Side Note: “lastIndex” seems to me to be an unfortunate property name because one might infer at first glance without reading further that it means lastIndex is the item at index str.length - 1 rather than what it actually means, the index of the character in the string where it left off last time)