EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

JS正则能用递归吗 #39

Open EdwardZZZ opened 6 years ago

EdwardZZZ commented 6 years ago
const str = 'Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/util/Map<Ljava/lang/String;Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/util/Set<Ljava/lang/Integer;>;>;>;>;>;>;';

const regexp = /L[^<]+<(.+;)>/;

let arr = [str];

while (true) {
    const result = arr[arr.length - 1].match(regexp);
    if (result) {
        arr[arr.length] = result[1];
    } else {
        break;
    }
}

console.log(arr);