我想在分割后找到带有字符串索引的左括号和右括号对,例如提供字符串
var str="class User{ constructor(name=null){ if(name !=null){ this.name=name; }else{
this.name=`Created by Test`; } } sayHello(){
console.log(`Welcome to Testing`); }
showName(){ console.log(`This is ${this.name} this side`);
if(true){ }else{ } } } function testing(){};
class Details { constructor(name=null){ if(name !=null){ this.name=name; }else{
this.name=`Created by Tester`; } }
sayName(){ console.log(`Welcome to Test2`); } }";
str=str.split(' ').filter(n => n).join(' '); //replaces extra spaces with none
var strArr= str.split(" "); //by using this array of string find index pair,
我必须找到每个类的开头关闭对的数组,例如[{'class':'User','index_pair':[11,类括号的关闭索引]},{'class':'Details, 'index_pair':[该类括号的开头索引,类括号的结尾索引]}]
谢谢!感谢您的帮助