If the target is just the common English accents, it’s easy to list them one by one. I would do a regex with the following blocks:
A-Za-z
upper and lower case without accent
áàâãéèêíïóôõöúç
ñ: accentuated vowels of Portuguese, cedilla and others of lambuja, lowercase
ÁÀÂÃÉÈÊÍÏÓÔÕÖÚÇÑ
: accentuated vowels of Portuguese, cedilla and other lambuja vowels, uppercase
spaces
Therefore:
/^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+$/
Or, leaving the lowercase/upper case distinction for implementation:
/^[a-záàâãéèêíïóôõöúçñ ]+$/i
So to use with 0-9, a-z, A-Z and 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;
?>
Why the space at the end of the regex group?
– user28595
Hey, it worked out! Thanks.
– Gabriel Henrique
@EGDEV The Code has occurred correctly but is with accent error. How do I remove it?
– Gabriel Henrique
Could report the error?
– usuario