package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?i)(?:line(\d+)\R)?(\d{2}(?::\d{2}){2}\.\d{2,3})\s*-->\s*(\d{2}(?::\d{2}){2}\.\d{2,3})\R((?:[^\r\n]|\r?\n[^\r\n])*)(?:\r?\n\r?\n|$)`)
var str = `WEBVTT FILE
line1
00:00:00.000 --> 00:00:10.000
‘Stuff’
line2
00:00:10.000 --> 00:00:20.000
Other stuff
Example with 2 lines
line3
00:00:20.00 --> 00:00:30.000
Example with only 2 digits in milliseconds
line4
00:00:30.000 --> 00:00:40.000
Different stuff
00:00:40.000 --> 00:00:50.000
Example without a head line`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/