This my simple data : <table></table><table></table><table>aaa</table>
how to replace <table></table><table></table>***<table>aaa</table>***
it should be return <table></table><table></table>
This my simple data : <table></table><table></table><table>aaa</table>
how to replace <table></table><table></table>***<table>aaa</table>***
it should be return <table></table><table></table>
If you just want to get the last <table>
element, then you can perhaps use this pattern:
.*(<table>.*</table>)
This will capture the last <table>.*</table>
into group 1 (see on rubular.com).
That said, you probably shouldn't use regex to parse HTML. If at all possibly, use an HTML parser.
$txt = '<table></table><table></table><table>aaa</table>';
print preg_replace('@(.*)(<table>aaa</table>)$@','\\1***\\2***',$txt);