所以我尝试在动态创建的行之间获取文本。
示例字符串
KOR/4
1/FI222/24NOV/DOK
PLO
134-57623905WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
/STACKI
89a7/SOMET
134-12389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/BLA
2736/2832
134-34389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/DYN
asdjadhjahd
134-57627905WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/STACKI
SSR/TROPPER5
FINAL
所以我尝试使用.match()和exec()。 我想不出一种方法来获取数组中数字之间的文本
所需的输出
// OUTPUT EXAMPLE
[0][
134-57623905WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
/STACKI
89a7/SOMET
],
[2][
134-12389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/BLA
2736/2832
],
[3][
134-34389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/DYN
asdjadhjahd
]
等等。
答案 0 :(得分:1)
您可以使用正则表达式获取字符串的目标部分。
var match = str.match(/\d{3}-.*?(?=\d{3}-|FINAL)/sg);
正则表达式选择字符串的任何部分,其长度为3的数字开始,以长度为3的数字结束
var str = document.getElementById("str").innerHTML;
var match = str.match(/\d{3}-.*?(?=\d{3}-|FINAL)/sg);
console.log(match.join('\n\n'));
<div id="str" style="display:none">KOR/4
1/FI222/24NOV/DOK
PLO
134-57623905WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
/STACKI
89a7/SOMET
134-12389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/BLA
2736/2832
134-34389783WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/DYN
asdjadhjahd
134-57627905WINLOSE/WINNER/ROBO
/TRY
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
DIM/K0/CMT44-30-30/5
/STACKI
SSR/TROPPER5
FINAL</div>