$pattern = '@<'.$tagname.'[^<>]*?>[^</'.$tagname.'>]*?$@si'
in addition, i guess my use of the ungreedy-modifying '?' in the second portion there is useless, since it will only match if it runs up to the end of the string (thus no amount of (un)greediness will change the matching nature)?
EDIT: solved it myself. needed to use a lookahead pattern, to make sure that it was matching the tag, any number of any character, that was NOT followed by the closing tag. current pattern:
$pattern = '@<'.$tagname.'[^<>]*?>.*?(?!</'.$tagname.'>)$@si';