If the target is just the accents common in Portuguese, it is easy to list them one by one. I would make a regex with the following blocks:
-
A-Za-z
case not accented
-
áàâãéèêíïóôõöúç
ñ: accentuated vowels of Portuguese, cedilla and others of lambuja, lowercase
-
ÁÀÂÃÉÈÊÍÏÓÔÕÖÚÇÑ
: accentuated vowels of Portuguese, cedilla and others of lambuja, upper case
spaces
Therefore:
/^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+$/
Or, leaving the lowercase / uppercase distinction for the implementation:
/^[a-záàâãéèêíïóôõöúçñ ]+$/i
So to use with 0-9, a-z, A-Z and with accents:
<?php
$text = "O pessoal do #Stackoverflow são ótimos em #programação.";
$text = preg_replace('/(?<!\S)#([0-9a-zA-ZáàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ_]+)/', '<a href="http://meusite.com/hashtag/$1">#$1</a>', $text);
echo $text;
?>