简体   繁体   中英

Remove repeated chars completely (regex/C#)

Looking for a one line C# code that would remove repeated chars from a string. Have done it with a simple loop with look-ahead but like to see a regex soln. Ex. input = "6200032111623451123345666" output = "623262345245"

Thanks.

Lyle

How about:

string s = Regex.Replace("6200032111623451123345666", @"(.)\1+", "");

The \\1+ is "one or more" (greedy) of the back-reference to the first capture-group, . (any character).

s /(([a-zA-z0-9])\\ 1 +)// g当然你需要把它翻译成c#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM