December 23rd, 2013, 02:56 AM
Is this a bug or something I don't understand...
I enter something under in Console of Chrome DevTools:
why /(a)?/.exec("caandy") don't get ["a", "a"] ?
December 23rd, 2013, 05:59 AM
Because the "a" is optional. Chrome checked the first letter to do due diligence: in the first example it didn't match while in the second example it did. It didn't have to do any more work beyond that. Heck, it didn't even have to do that at all, but it might be programmed so that it begins checking the string before/while it's "compiling" the regex.
Last edited by requinix; December 23rd, 2013 at 06:05 AM.