$re = '/(?<=\s|^)(№)(?=\d+(\s|$))/';
$str = 'Мороз и солнце; день чудесный №1 !
Еще ты дремлешь, №2 друг прелестный -
№3 Пора, красавица№4, проснись:
Открой №5 сомкнуты негой взоры
№6Навстречу северной Авроры,
Звездою севера явись!';
$subst = "номер";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php