当前位置:编程学习 > C#/ASP.NET >>

时间匹配,YYYY/MM/DD

页面数据有很多内容,其中有时间数据,

例如  

漳州市中国医院大楼中心改扩建医用电梯批量采购项目招标公告 
 
发布时间:2012/5/16  |  浏览次数:180 
 
招标编号:HXZ(漳)1204534535401号
 
假如这么一段话,要求正则匹配到 2012/5/16  这个,

 这个正则怎么写啊?
 
--------------------编程问答-------------------- string input=@"漳州市中国医院大楼中心改扩建医用电梯批量采购项目招标公告 

发布时间:2012/5/16 | 浏览次数:180 

招标编号:HXZ(漳)1204534535401号";
string regs1 = Regex.Match(input, @"^\d{4}/(0?[1-9]|1[0-2])/((0?[1-9]|[1-2][0-9])|3[0-1])$").Value; --------------------编程问答--------------------
		string s = @"漳州市中国医院大楼中心改扩建医用电梯批量采购项目招标公告

发布时间:2012/5/16 | 浏览次数:180

招标编号:HXZ(漳)1204534535401号";
Match match = Regex.Match(s, @"\d{4}/\d{1,2}/\d{1,2}");
Response.Write(match.Value);
--------------------编程问答--------------------

 string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx

                string pattern = @"\d{4}([/-])\d{1,2}\1\d{1,2}";

                tempStr = Regex.Match(tempStr, pattern).Value;//2012/5/16
--------------------编程问答-------------------- ^\d{4}[-/.]([1-9]|(1[0-2]))[-/.]([1-9]|([12]\d)|(3[01]))$  --------------------编程问答--------------------
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,