这段正则使用了前瞻的方法,匹配的数字后面必须有3的n倍个数字,保证3个为1组,并将匹配出来的数字后面添加逗号。(正负数通杀)
class="code_img_closed" src="/Upload/Images/2013071417/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('e8d168b6-5288-48aa-93b6-33e6b924f0f0',event)" src="/Upload/Images/2013071417/2B1B950FA3DF188F.gif" alt="" />1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Text.RegularExpressions; 6 using System.Threading.Tasks; 7 8 namespace MyRegexTest 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 List<string> list = new List<string>() { "1", "12", "123", "1234", "12345", "123456", "1234567", 15 "12345678", "123456789", "1234567890"}; 16 foreach (var s in list) 17 { 18 Console.WriteLine(Regex.Replace(s, @"(\d+?)(?=(?:\d{3})+$)", "$1,")); 19 } 20 21 Console.ReadKey(); 22 } 23 } 24 }View Code
refer to:http://www.cnblogs.com/fysn/archive/2012/02/24/2367024.html