I need to preform a preg_replace for every empty line that is not followed by this:
00:00:02.800 --> 00:00:04.800
Its format is:
any 2 digits:any 2 digits:any 2 digits.any 3 digits --> any 2 digits:any 2 digits:any 2 digits.any 3 digits
I know how to search for an empty line:
"/(^[
]*|[
]+)[\s\t]*[
]+/"
And for the time row :
[0-9]{1,2}[:.,-]?[:][0-9]{1,2}[:.,-]?[:][0-9]{1,2}[:.,-]?[.][0-9]{1,3}[:.,-]?[\s][-][-][>][\s][0-9]{1,2}[:.,-]?[:][0-9]{1,2}[:.,-]?[:][0-9]{1,2}[:.,-]?[.][0-9]{1,3}[:.,-]?
But I wasn't able to create a regex that finds only the lines that are not followed by the time row.
EDIT: OPTION 1 File Input:
WEBVTT
00:00:00.300 --> 00:00:01.000
line1
line2
line3
00:00:01.000 --> 00:00:02.800
line1
00:00:02.800 --> 00:00:04.800
line1
line2
line3
File desired output:
WEBVTT
00:00:00.300 --> 00:00:01.000
line1
line2
line3
00:00:01.000 --> 00:00:02.800
line1
00:00:02.800 --> 00:00:04.800
line1
line2
line3
My function:
$content = preg_replace("/regex expresion/", "", $file_content);
EDIT 2:
Just found out I need to find another format: OPTION 2 File Input:
1
00:00:00,300 --> 00:00:01,000
line 1 line 1
line 2
2
00:00:01,000 --> 00:00:02,800
line 1 line 1 line 1
line2
line 3 line 3
3
00:00:02,800 --> 00:00:04,800
line 1
File desired output:
1
00:00:00,300 --> 00:00:01,000
line 1 line 1
line 2
2
00:00:01,000 --> 00:00:02,800
line 1 line 1 line 1
line2
line 3 line 3
3
00:00:02,800 --> 00:00:04,800
line 1
Totos answer worked great. I tried to modify it to my need and was unsuccessful. I tried:
/(\R){1,}(?!(\d\R\d\d:\d\d:\d\d\.\d{3}) --> (?2))
Solved
Solution:
option 1:
$regex = "/(\R){1,}(?=(\d\d:\d\d:\d\d\.\d{3}) --> (?2))/";
option 2:
$regex = "/(\R)(?!(\d\R\d\d:\d\d:\d\d\,\d{3}))/";