当前位置: 代码迷 >> ASP.NET >> 正则提取域名(急)
  详细解决方案

正则提取域名(急)

热度:4319   发布时间:2013-02-25 00:00:00.0
正则提取域名(急~~~在线等)
我从网页获取了一段域名列表如下:

06my.net
06yonetici.com
06zg.com
07-tour.net
0701togo.com
0707win.com
070911.com
0710mrw.com
07111.info
0717wz.com
0722home.com
0731hsp.com
0731move.com
0736-0769.org
0752tg.net
075577.com
07559999.com
0755rr.com
0756bear.com
0756home.net
0769winwin.com
07873.com
078vy1s.biz
0792home.com
0797jlf.com
07ey6y6t.biz
080123.com
080208.net
08122007.com
0816banjia.info
0816baojie.info
0871pc.net
0898cct.com
0898hncq.com
08c98d34fa.com
0906.cc
090917.com
0932wx.com
0969mchi32.biz
099117173.net
0998tq.com
09good.com
09mpile.com
0a4jdtj4n.info


请问把这个记录一条一条的读出来的正则表达式该怎么写?

------解决方案--------------------------------------------------------
.+\.[a-zA-Z]+

------解决方案--------------------------------------------------------
C# code
string domains = @"06my.net06yonetici.com06zg.com07-tour.net0701togo.com0707win.com070911.com0710mrw.com07111.info0717wz.com0722home.com0731hsp.com0731move.com0736-0769.org0752tg.net075577.com07559999.com0755rr.com0756bear.com0756home.net0769winwin.com07873.com078vy1s.biz0792home.com0797jlf.com07ey6y6t.biz080123.com080208.net08122007.com0816banjia.info0816baojie.info0871pc.net0898cct.com0898hncq.com08c98d34fa.com0906.cc090917.com0932wx.com0969mchi32.biz099117173.net0998tq.com09good.com09mpile.com0a4jdtj4n.info"; string [] domainArrary=Regex.Replace(domains,@"\s+",",").TrimStart(',').TrimEnd(',').Split(',');
------解决方案--------------------------------------------------------
这个用不着正则吧? 
string[] array = domains.Split(new string[] { "\r\n"}, StringSplitOptions.RemoveEmptyEntries);

------解决方案--------------------------------------------------------
用这个正则也行 ^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|
ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|
bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|
ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|
ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|
gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|
il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|
kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|
ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|
ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|
pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|
si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|
tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|
vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2]
[0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2]
[0-4][0-9]|[2][5][0-5]))$
------解决方案--------------------------------------------------------
C# code
int num=4;//定义位数                string pattern_domain = string.Format(@"(?<=^|\s)\S{{{0}}}\.\S+",num);                string[] temp_arr = Regex.Matches(domains, pattern_domain).Cast<Match>().Select(a => a.Value).ToArray();
  相关解决方案