I'm using Perl for this regular expression question, but it would be good to know if it applies to PHP, as well.
I need to comment out all print statements or all things that start with print in a PHP file. It looks something like this:
<?php
// Description of file
...
print("Foobar");
// print("Foo");
//print("bar");
// Open and print file
function printtemplate($file) {
...
}
...
printtemplate($file);
...
?>
To start with, I formulated a regular expression like this:
((?<!function )|(?<!//))print
It obviously does not work because the |
is an OR. I'm looking for an AND so that both negative look-behind assertions need to be true. Does the AND construct exist in some form in regular expressions or is there a way to simulate one?
Ultimately, I want the php file to look like the following, after the regular expression is applied:
<?php
// Description of file
...
//print("Foobar");
// print("Foo");
//print("bar");
// Open and print file
function printtemplate($file) {
...
}
...
//printtemplate($file);
...
?>
Any help would be appreciated. Thank you.