0

I'm trying to format emojis in my html page with a regex replace code in c#, but the code work fine in regex testers but not working in C#.

Pattern

/&(?:\#(?:(?<dec>[0-9]+)|[Xx](?<hex>[0-9A-Fa-f]+))|(?<named>[A-Za-z0-9]+));/

Value

teste &#128512;&#128513;&#128514;

Result

teste <span class='emoji'>&#128512;</span><span class='emoji'>&#128513;</span><span class='emoji'>&#128514;</span>

You can test in https://rgxdb.com/try

My C# code

public static string FormatTextEmoji(string pText)
{
    //Armazena o retorno
    string lReturn = pText;
    //Seta a expressão
    string lExpression = @"/&(?:\#(?:(?<dec>[0-9]+)|[Xx](?<hex>[0-9A-Fa-f]+))|(?<named>[A-Za-z0-9]+));/";
    //Ignora o case
    Regex lRegex = new Regex(lExpression, RegexOptions.IgnoreCase);
    //Seta a notícia com os links
    lReturn = lRegex.Replace(lReturn, "<span class=\"emoji\">$1</span>");
    //Retorna o valor
    return lReturn;
}

I have another Regex Replace that working fine, i tried a lot of modifications but no success.

Anyone can help me ?

Temani Afif
  • 245,468
  • 26
  • 309
  • 415

0 Answers0