$test = "<div><b><i>#uniquetag#</b></i></div> <div>Keep this</div>";
$test = preg_replace("/<div(.*)#uniquetag#(.*)<\/div>/i", "#uniquetag#", $test);
I want the result to be
$test = "#uniquetag# <div>Keep this</div>";
But it returns
$test = "#uniquetag#";
I think I know why. (.*) is greedy and it extend the search till the end. But I can't figure out what is the correct way to do it.
Update:
Special thanks to ghostdog74. Old problem solved. A new problem is experienced....
$test = "<div></div> <div><b><i>#uniquetag#</b></i></div> <div>Keep this</div>";
$test = preg_replace("/<div(.*)#uniquetag#(.*?)<\/div>/i", "#uniquetag#", $test);
Expected result is
$test = "<div></div> #uniquetag# <div>Keep this</div>";
But it turns out to be
$test = "#uniquetag# <div>Keep this</div>";
Again, I believe that's because of the first (.). Changing it to (.?) won't help also. Need to think of a way to exclude .