正则提取域名字符串的长度
我有一组(listbox控件)这样的域名,如何按规则把域名长度为3(如:xxx.com)、4位(如:xxxx.com)的提出来;
另外域名的组成也有可能是xxx.com.cn这样的组合
[解决办法]
- C# code
string source = "xxx.com xxxx.com xxxx.cc"; Regex reg = new Regex(@"[\S]{3,4}.[\S]+"); MatchCollection mc = reg.Matches(source); foreach (Match m in mc) { MessageBox.Show(m.Value); }
[解决办法]
[解决办法]
按位数提取
- C# code
int num=4;//定义位数 string pattern_domain = string.Format(@"(?i)(?<=^|\s)\S{{{0}}}\.com(\.cn)?",num); string[] temp_arr = Regex.Matches(domains, pattern_domain).Cast<Match>().Select(a => a.Value).ToArray();