String separation error occurred in solving stringObject.split (RegExp)?

The

string.split (RegExp) method uses regular expressions to separate strings. An error occurs when the regular expression contains parentheses (), but the value returned through string.match (RegExp) is that I want the correct
for example

.
var str = " 020-12345678020-87654321  88888888  ";
var reg = /(\d{3}-)?\d{7,9}/g;
var phones = str.match(reg);
console.log(phones);
var arr = str.split(reg);
console.log(arr);
var element = [];
for(var i=0;i<arr.length;iPP){
    var item = {
        text:arr[i],
        click:false
    }
    element.push(item);
    if(i==arr.length-1){
        break;
    }
    var item2 = {
        text:phones[i],
        click:true
    }
    element.push(item2);
}
console.log(element);

then my ideal return result is

clipboard.png


str.split(reg)undefined

clipboard.png
causes a bigger error in the loop that follows me. How to deal with the problem of adding parentheses in solving the rule?


the reason is that when dealing with regularities with capture groups, split will treat the data captured in the capture group as part of the segmented result. As follows:

the code is as follows:

var str="abclskd,jsldk-lskdfj778,jsdkf*jdkf";
var regex1=/[,*-]/;
str.split(regex1);
(5) ["abclskd", "jsldk", "lskdfj778", "jsdkf", "jdkf"]

var regex2=/([,*-])/;
str.split(regex2);
(9) ["abclskd", ",", "jsldk", "-", "lskdfj778", ",", "jsdkf", "*", "jdkf"]

var regex3=/(?:[,*-])/;
str.split(regex3);
(5) ["abclskd", "jsldk", "lskdfj778", "jsdkf", "jdkf"]

so, in order not to have such a result, you change () to (?)

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-1b308e7-340d2.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-1b308e7-340d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?