I have sets of specific words that i want to detect them in subtitle and then remove entire line with regex:
$forbiddenWords = [
'Ads',
'Download',
//
];
$file = file_get_contents('example.srt');
foreach ($forbiddenWords as $word) {
$file .= preg_replace("/\d{3}(?!.*?-)[\s\S]*?$word\[\s\S]*?(?=\d)/", '', $file);
}
Lines of subtitle:
1
00:00:39,243 --> 00:00:45,820
This line is ok
2
00:00:46,243 --> 00:00:51,820
This line with
"Ads" word should be deleted
and next line
3
00:01:04,243 --> 00:01:05,820
This line with
"Download" word should be deleted
and next line
4
00:01:08,664 --> 00:01:12,331
An ok line
The output i want :
1
00:00:39,243 --> 00:00:45,820
This line is ok
2
00:00:46,243 --> 00:00:51,820
3
00:01:04,243 --> 00:01:05,820
4
00:01:08,664 --> 00:01:12,331
An ok line
My regex doesn't work and it captures multiple lines DEMO REGEX