I noticed a problem with the "What's Related" box - it would only add links up to the first image. So I took a look at the function, made it more efficient, and fixed the problem.
The main difference in the match is that this one doesn't recognize any tags in between <a href=""> and </a>. So, for example, <a href="..."><b>foo</b></a> will not be matched. Maybe I'll futz around with it to handle this if anyone's interested.
function COM_extractLinks( $fulltext, $maxlength = 26 )
{
$rel = array();
preg_match_all( "/(<a href=[^>]+>

([^<]*)(</a>

/i", $fulltext, $matches );
for ( $i=0; $i< count( $matches[0] ); $i++ )
{
// if link is too long, shorten it and add ... at the end
if ( ( $maxlength > 0 ) && ( strlen( $matches[2][$i] ) > $maxlength ) )
{
$matches[2][$i] = substr( $matches[2][$i], 0, $maxlength - 3 ) . '...';
$matches[0][$i] = $matches[1][$i] . $matches[2][$i] . $matches[3][$i];
}
$rel[] = COM_checkHTML( $matches[0][$i] );
}
return $rel;
}
[Note I did not post this in HTML mode because it changed some of the code into smilies...]