Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

regex to replace accents

$
0
0
I have this regex to replace accents but it fails if the text contains "|".
string Text = "word|word2";

C#
// Regex.
System.Text.RegularExpressions.Regex replace_a_Accents = new System.Text.RegularExpressions.Regex("[á|à|ä|â]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_e_Accents = new System.Text.RegularExpressions.Regex("[é|è|ë|ê]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_i_Accents = new System.Text.RegularExpressions.Regex("[í|ì|ï|î]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_o_Accents = new System.Text.RegularExpressions.Regex("[ó|ò|ö|ô]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_u_Accents = new System.Text.RegularExpressions.Regex("[ú|ù|ü|û]", System.Text.RegularExpressions.RegexOptions.Compiled);// Reemplaza.
Texto_Retorno = replace_a_Accents.Replace(Texto_Retorno, "a");
Texto_Retorno = replace_e_Accents.Replace(Texto_Retorno, "e");
Texto_Retorno = replace_i_Accents.Replace(Texto_Retorno, "i");
Texto_Retorno = replace_o_Accents.Replace(Texto_Retorno, "o");
Texto_Retorno = replace_u_Accents.Replace(Texto_Retorno, "u");

Viewing all articles
Browse latest Browse all 224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>