I have php file, and I want to remove closing tag (?>), but only if it is last closing tag and there is nothing after.
<?php
//some code
?>
<?php
//some other code
?> // <- this and only this should be removed
I have tried pattern 's/(\s*\?>\s*)$//s' and several of its mutations, but with no success: they remove all occurrences of ?>, breaking the code, and I don't know how to match EOF.
(Yes, I know a workaround: using e.g. tail -1 to check only last line of file, but it would complicate my whole code-formatting script, so if the problem can be resolved with properly constructed regex, it would be great.)
perl -p -i -e 's/(\s*\?>\s*)$//' filename.php, then each line is processed one at a time. Obviously, this will strip all occurrences.