The RegExp object is discarded after it is executed once. Therefore, each time you use RegExp, you need to create a new one. The following is an example. If you need a RegExp object, you can refer to the following code, is to identify the year, month, and day from the string. You can see that the created rYMD RegExp object is executed once and then again.
Var DateStr = "2014-9-8"; var rYMD = new RegExp ("(\ d {4} | \ d {2 }) -(\ d {2} | \ d {1})-(\ d {2} | \ d {1}) "," g "); var aRt = rYMD.exe c (DateStr); var srt1_rymd.exe c (DateStr );
After debugging, it is found that the first execution, aRt gets the returned Array (Array), but the sRt followed by it is null.
After repeated attempts, it was found that the RegExp object was discarded after being executed once.
Therefore, you must note that each time you use RegExp, you need to create a new one.