Click here to Skip to main content
15,171,576 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionMessage Closed Pin
18-Jan-22 22:58
MemberMember 1550515318-Jan-22 22:58 
AnswerRe: Matching a unknown range of lines Pin
Pete O'Hanlon18-Jan-22 23:37
mvaPete O'Hanlon18-Jan-22 23:37 
Questionregex related query Pin
Member 154859391-Jan-22 9:23
MemberMember 154859391-Jan-22 9:23 
AnswerRe: regex related query Pin
Gerry Schmitz1-Jan-22 9:45
mveGerry Schmitz1-Jan-22 9:45 
QuestionFind and Replace starting... until Pin
Roland Plomp31-Dec-21 5:11
MemberRoland Plomp31-Dec-21 5:11 
QuestionHow do I make this CASE INSENSATIVE? Pin
RapidDonO23-Dec-21 2:13
MemberRapidDonO23-Dec-21 2:13 
AnswerRe: How do I make this CASE INSENSATIVE? Pin
jschell23-Dec-21 7:09
Memberjschell23-Dec-21 7:09 
QuestionHow to eliminate Pattern if Contains specific words Pin
RapidDonO20-Dec-21 6:30
MemberRapidDonO20-Dec-21 6:30 
AnswerRe: How to eliminate Pattern if Contains specific words Pin
Richard Deeming4-Jan-22 0:32
mveRichard Deeming4-Jan-22 0:32 
QuestionRegular expression to extract row 3 Pin
DanVanClan17-Nov-21 3:53
MemberDanVanClan17-Nov-21 3:53 
Questionfail2ban regex matching on testing sites but not fail2ban itself Pin
murdocklawless4-Nov-21 2:07
Membermurdocklawless4-Nov-21 2:07 
AnswerRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
Richard MacCutchan4-Nov-21 3:07
mveRichard MacCutchan4-Nov-21 3:07 
GeneralRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
murdocklawless4-Nov-21 3:49
Membermurdocklawless4-Nov-21 3:49 
AnswerRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
Peter_in_27804-Nov-21 4:17
professionalPeter_in_27804-Nov-21 4:17 
GeneralRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
murdocklawless4-Nov-21 4:31
Membermurdocklawless4-Nov-21 4:31 
GeneralRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
Peter_in_27804-Nov-21 13:05
professionalPeter_in_27804-Nov-21 13:05 
GeneralRe: fail2ban regex matching on testing sites but not fail2ban itself Pin
murdocklawless4-Nov-21 14:10
Membermurdocklawless4-Nov-21 14:10 
QuestionEditing my existing Regex Pin
Member 154173673-Nov-21 2:14
MemberMember 154173673-Nov-21 2:14 
Questionregex to replace accents Pin
Member 1489067816-Sep-21 4:50
MemberMember 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
MemberMember 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

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.