Click here to Skip to main content
15,792,870 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionEditing my existing Regex Pin
Member 154173673-Nov-21 2:14
Member 154173673-Nov-21 2:14 
Questionregex to replace accents Pin
Member 1489067816-Sep-21 4:50
Member 1489067816-Sep-21 4:50 
AnswerRe: regex to replace accents Pin
Richard Deeming16-Sep-21 5:28
mveRichard Deeming16-Sep-21 5:28 
GeneralRe: regex to replace accents Pin
Richard MacCutchan16-Sep-21 5:44
mveRichard MacCutchan16-Sep-21 5:44 
GeneralRe: regex to replace accents Pin
Richard Deeming16-Sep-21 5:55
mveRichard Deeming16-Sep-21 5:55 
GeneralRe: regex to replace accents Pin
Richard MacCutchan16-Sep-21 6:05
mveRichard MacCutchan16-Sep-21 6:05 
GeneralRe: regex to replace accents Pin
Member 1489067816-Sep-21 6:38
Member 1489067816-Sep-21 6:38 
GeneralRe: regex to replace accents Pin
Richard Deeming16-Sep-21 6:54
mveRichard Deeming16-Sep-21 6:54 
Regex can do the job. But running five+ separate regex operations on a string just to replace a few letters with their unaccented alternatives is overkill.

The other option, which is even nastier and less obvious, is to use Unicode normalization:
C#
static string RemoveDiacritics(string stIn)
{
    string stFormD = stIn.Normalize(NormalizationForm.FormD);
    StringBuilder sb = new StringBuilder();

    for(int ich = 0; ich < stFormD.Length; ich++) 
    {
        UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
        if (uc != UnicodeCategory.NonSpacingMark) 
        {
            sb.Append(stFormD[ich]);
        }
    }

    return sb.ToString().Normalize(NormalizationForm.FormC);
}
C#
string input = "Príliš žlutoucký kun úpel dábelské ódy.";
string result = RemoveDiacritics(input); // "Prilis zlutoucky kun upel dabelske ody."
Source[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: regex to replace accents Pin
Member 1489067816-Sep-21 6:39
Member 1489067816-Sep-21 6:39 
AnswerRe: regex to replace accents Pin
Peter_in_278016-Sep-21 5:45
professionalPeter_in_278016-Sep-21 5:45 
QuestionRegex Match with Multiple Words, I need you to not use leading and trailing spaces. Pin
Member 1489067816-Sep-21 4:07
Member 1489067816-Sep-21 4:07 
QuestionTrying to match a string with many backslashes Pin
Florian Rammler31-Aug-21 2:35
Florian Rammler31-Aug-21 2:35 
AnswerRe: Trying to match a string with many backslashes Pin
Richard Deeming31-Aug-21 3:55
mveRichard Deeming31-Aug-21 3:55 
QuestionRegex to match exact word and dash symbol Pin
Member 1533502224-Aug-21 10:28
Member 1533502224-Aug-21 10:28 
AnswerRe: Regex to match exact word and dash symbol Pin
OriginalGriff24-Aug-21 10:32
mvaOriginalGriff24-Aug-21 10:32 
GeneralRe: Regex to match exact word and dash symbol Pin
Member 1533502224-Aug-21 11:00
Member 1533502224-Aug-21 11:00 
AnswerRe: Regex to match exact word and dash symbol Pin
User 1521787324-Aug-21 18:47
User 1521787324-Aug-21 18:47 
GeneralRe: Regex to match exact word and dash symbol Pin
Member 1533502224-Aug-21 23:57
Member 1533502224-Aug-21 23:57 
GeneralRe: Regex to match exact word and dash symbol Pin
User 1521787325-Aug-21 0:32
User 1521787325-Aug-21 0:32 
GeneralRe: Regex to match exact word and dash symbol Pin
Member 1533502225-Aug-21 0:37
Member 1533502225-Aug-21 0:37 
GeneralRe: Regex to match exact word and dash symbol Pin
User 1521787325-Aug-21 1:08
User 1521787325-Aug-21 1:08 
GeneralRe: Regex to match exact word and dash symbol Pin
Member 1533502225-Aug-21 1:24
Member 1533502225-Aug-21 1:24 
GeneralRe: Regex to match exact word and dash symbol Pin
User 1521787325-Aug-21 2:11
User 1521787325-Aug-21 2:11 
QuestionProblem capturing last group in a line: CLOSED Pin
mo149222-Aug-21 14:18
mo149222-Aug-21 14:18 
AnswerRe: Problem capturing last group in a line: CLOSED Pin
Richard Deeming22-Aug-21 22:46
mveRichard Deeming22-Aug-21 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.