preg_match('#src="http:\/\/captcha\.yandex\.net\/image\?key=([a-f0-9]{32})"#i',$str,$matches); echo $matches[1];