I am having a problem using regular expressions to strip out code contained within certain comments. The problem is that there are multiple sets of comments and my expression is being greedy and striping out everything from the first comment until the last one.
My string looks like:
Code1 <!-- Mark Begin --> Code2 <!-- Mark End --> Code3 <!-- Mark Begin --> Code4 <!-- Mark End --> Code5
Here is my search and replace:
<?
$begin='<!-- Mark Begin -->';
$end='<!-- Mark End -->';
$regx=$begin."(.)*?".$end;
$new_string=eregi_replace($regx,"",$old_string);
?>
This results in $new_string looking lik:
Code1 Code5
I have tried to prevent the match from including another copy of the $begin string by adding a negated class of characters like:
[($begin)] to replace the (.) but I get an error.
What I want is:
Code1 Code3 Code5
Any ideas?
Thanks