使用正则表达式重复的数字 [英] Duplicated numbers using Regex

查看:84
本文介绍了使用正则表达式重复的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何使用正则表达式删除唯一的重复号码?! 

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

ex:

1235192649

1235192649

输出应为:3564

并提前感谢。

推荐答案

显然,这不是你寻求的解决方案,但它可能会让你指向正确的方向..

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,
                                    string.Empty);}
// ***********************************************************


这篇关于使用正则表达式重复的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆