The problem of exec method matching in JavaScript

The

exec method, which shows different results after the same piece of code is commented out, is strange.

the same code, comment out the top and bottom, the result is not the same?
var myRe=/d (b +) console.log;
console.log (myRe.exec ("cdbbdbsdbdbz"));
console.log) (myRe.exec (" cdbbdbsbbdbz"));
console.log) (myRe.exec ("cdbbdbsdbdbz"));

)
Mar.02,2021

your two sentences are the same. The first sentence is commented out, and the following sentence is equivalent to the first sentence.


the subject understands the lastIndex attribute of the regular object,

.

to put it shallowly,

the result returned each time is a rematch from the next location from the previous match, so the result returned by using exec several times may be different.

strongly condemns the subject of posting screenshots where the code should be posted!


when regular expressions use the "g" flag, you can execute the exec method multiple times to find a successful match in the same string. When you do this, the search starts at the location specified by the lastIndex attribute of the regular expression.

https://developer.mozilla.org.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b354ff-2b6ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b354ff-2b6ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?