Reputation: 756
In a file, I replace a marker !!marker!!
by a string or nothing:
if ($foo){
insert_content('index.html', 'index.html', '!!marker!!', $string);
}else{
insert_content('index.html', 'index.html', '!!marker!!', '');
}
…but as !!marker!!
was on its own blank line, this line remains, and blank.
Is it possible to replace the marker by nothing and remove the line it was on?
Upvotes: 1
Views: 171
Reputation: 67978
[^\n]*!!marker!![^\n]*\n
This should remove the line .Replace by empty string
.See demo.
https://regex101.com/r/sJ9gM7/112
$re = "/[^\\n]*!!marker!![^\\n]*\\n/im";
$str = "asdasdasd\nsadasd !!marker!!a asdasd\nklklkl\na\nsd\nas\nd\n";
$subst = "";
$result = preg_replace($re, $subst, $str);
Upvotes: 2