Duplicated numbers using Regex RRS feed

  • Question

  • hello everyone ,
    how can i remove the only Duplicated numbers using Regex ?! 



    the output should be : 3564

    and thanks in advance.

    Saturday, December 29, 2018 8:16 PM

All replies

  • Clearly, this is not the solution you seek, but it might serve to get you pointed in the right direction ..

    // **********************************************************
                MatchCollection dupes;
                string digitSource = "2184332654467829";
                string pattern = @"(\d)(?=.*\1)";
                string z;
                // collect all duplicates
                dupes = Regex.Matches(digitSource, pattern);
                z = digitSource;
                // replace each duplicate with empty string.
                foreach (Match match in dupes) {
                         z = z.Replace( match.Groups[1].Value,
    // ***********************************************************

    • Proposed as answer by Lincoln_MA Sunday, December 30, 2018 4:21 PM
    Sunday, December 30, 2018 6:51 AM
  • Hi Taher Mahmoud,

    Do you try the method that Lincoln_MA mentioned. is it helpful to you. if the issue still exists, please feel free let me know.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, January 8, 2019 1:44 AM