SELECT
t1.link,
t1.name,
t1.txt,
if(t1.txt REGEXP "^<a(.*)><img(.*)/></a>$",
REPLACE(t1.txt, 'alt=""', CONCAT('alt="', (SELECT name FROM test_toster_102543 WHERE link=t1.link),'"')),
REPLACE(t1.txt, 'alt=""', CONCAT('alt="', t1.name,'"'))
) as txt_rgexp
FROM
test_toster_102543 t1