I would like to know what the regex would be for </sup> and </div> ? Or </a></sup> and </div> ? This is taking the first closing a and sup tags with the last closing div tag. But I want the last closing a and sup tags along with the last closing div tag: <?php $string = "<div><img src=\"/assets/images/copyChkboxOff.gif\" alt=\"Unchecked Copy Box\" class=\"copyBox hide-for-tablet\" data-bible-id=\"215010\"><a data-bible-id=\"215010\" data-type=\"tools\" href=\"/kjv/jdg/4/10/s_215010\" class=\"hide-for-tablet\">Jdg 4:10</a><span class=\"hide-for-tablet\"> - </span>And Barak <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H1301&t=KJV\">H1301</a></sup> called <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H2199&t=KJV\">H2199</a></sup> Zebulun <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H2074&t=KJV\">H2074</a></sup> and Naphtali <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H5321&t=KJV\">H5321</a></sup> to Kedesh; <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H6943&t=KJV\">H6943</a></sup> and he went up <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H5927&t=KJV\">H5927</a></sup> with ten <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H6235&t=KJV\">H6235</a></sup> thousand <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H505&t=KJV\">H505</a></sup> men <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H376&t=KJV\">H376</a></sup> at his feet: <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H7272&t=KJV\">H7272</a></sup> and Deborah <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H1683&t=KJV\">H1683</a></sup> went up <sup><a href=\"/lang/Lexicon/Lexicon.cfm?strongs=H5927&t=KJV\">H5927</a></sup> with him.</div>"; //$supdiv = "/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/"; //$supdiv = "/.*\(([^)]*)\)/"; //$supdiv = "/.*\(([^)]*)\)/"; $supdiv = "/<\/a><\/sup>(.*)<\/div>/";// /<\/sup>(.*)<\/div>/gm preg_match_all($supdiv, $string, $lastWords, PREG_SET_ORDER); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(!empty($lastWords) || $lastWords !== NULL){ echo "lastWords: <pre>"; var_dump($lastWords); echo "</pre><br /><br />\n"; } ?> </body> </html> PHP: