我需要使用正则表达式将 SRT 文件的数据作为数组获取。
到目前为止,这是我的代码:
Java脚本:
function readSrt() {
var srtUrl = 'assets/media/subtitles.srt';
$.get(srtUrl, function(data) {
console.log("SRT:", data); // it reads ok
var regexp = /(.*)\n(.*),\d\d\d --> (.*)\n(.*)/g; // this regex doesn't work
console.log("SUBS:", data.match(regexp)); // outputs null
});
}
字幕.srt:
0
00:00:00,000 --> 00:00:01,000
Instructor…All right, let's start off
1
00:00:01,000 --> 00:00:04,000
here. We were, I think, wrapping up kind
...
14
00:00:40,000 --> 00:00:42,000
mound, basically.
15
00:00:42,000 --> 00:00:44,000
If you go to Colossae today, none of it
...
需要获得:
1. 0
2. 00:00:00
3. 00:00:01,000
4. Instructor…All right, let's start off
在regex101.com中进行了几次尝试,但似乎只适用于 PHP 而不是 javascript。
我做错了什么,我该如何解决?