tags:

views:

55

answers:

2

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>

+1  A: 

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.

polygenelubricants
A: 
$txt = '<table></table><table></table><table>aaa</table>';
print preg_replace('@(.*)(<table>aaa</table>)$@','\\1***\\2***',$txt);
turbod