I’m having problem understanding Regular Expression. Here is what I’ve got
$pat = “/<[^>]*>/”;
This pattern works well in removing all the HTML tags. But when it’s used to remove <?php ?> tags, it has problem when -> exist in between the tag.
i.e
<?php
$obj->name;
$obj->reset();
?>
some other things outside
Intended result
some other things outside
The actual result
name;
$obj->reset();
?>
some other things outside
So, how can I exclude the -> in my search?
You can either code in a special exception for the
<?php ?>delimiters, so it takes precedence over the generic rule:Or you use an assertion. Wah no, that’s probably too difficult.(?=...)and allow->as alternative