The following code is a test that recognizes the year, month and day from the string. You can see that the created rYMD RegExp object was 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 = (DateStr); var sRt=(DateStr);
After debugging, it was found that the first execution, aRt got the returned Array (array), but the sRt immediately following it was null
After repeated attempts, it was found that the RegExp object was destroyed after executing it once.
Therefore, you need to pay attention to that you need to re-new one every time you use RegExp.