This question is Part 2 of PHP's preg_match_all() to pull out all php tags
I need to extend this regex /<\?.*?(?:\?>|$)/s to not match when it finds tags inside single or double quotes. This will involve back-referencing the matched quote type, which goes beyond my intuitive understanding of regex.
Example HTML:
<?
// Test xml
$this->_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$this->_xml .= "<TransferredValueTxn xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >\n";
$this->_xml .= "<?=$test?> <TransferredValueTxnReq>" . trans("test") . "\n";
?>
Hoped for Result:
[0] => "<?
// Test xml
$this->_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$this->_xml .= "<TransferredValueTxn xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >\n";
$this->_xml .= "<?=$test?> <TransferredValueTxnReq>" . trans("test") . "\n";
?>"
For future reference:
/<\?(?:.*?(?:(\"|').*?[^\\]\1)*)*(?:\?>|$)/sWork perfectly with all of my unit tests.