这是空白文字:
[Tiền Giang] DB: 092743 1: 99578 2: 09593 3: 93933 - 17703 4: 04433 - 62172 - 47622 - 95029 - 80836 - 15012 - 30888 [Kiên Giang] DB: 564242 1: 03204 2: 49541 3: 79330 - 49374 4: 84491 - 10327 - 95832 - 61630 - 90692 - 28793 - 28600
我想得到:
(0) [Tiền Giang]
(1) DB: 092743 1: 99578 2: 09593 3: 93933 - 17703 4: 04433 - 62172 - 47622 - 95029 - 80836 - 15012 - 30888
(0) [Kiên Giang]
(1) DB: 564242 1: 03204 2: 49541 3: 79330 - 49374 4: 84491 - 10327 - 95832 - 61630 - 90692 - 28793 - 28600
...
我得到(0):(\[(.*?)\]\s).exec(text)
;
但是(1)任何想法..
答案 0 :(得分:2)
我认为你可以使用2个被捕获的小组来做到这一点。
var str = "[Tiền Giang] DB: 092743 1: 99578 2: 09593 3: 93933 - 17703 4: 04433 - 62172 - 47622 - 95029 - 80836 - 15012 - 30888 [Kiên Giang] DB: 564242 1: 03204 2: 49541 3: 79330 - 49374 4: 84491 - 10327 - 95832 - 61630 - 90692 - 28793 - 28600 ";
var pattern = /(\[.+?])([^[]+)/g;
var matches;
while ((matches = pattern.exec(str)) !== null) {
console.log("(0) " + matches[1]);
console.log("(1) " + matches[2]);
}

(\[.+?\])
([^[]+)