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
str.split(reg)undefined
causes a bigger error in the loop that follows me. How to deal with the problem of adding parentheses in solving the rule?