帮写一正则表达式. 本帖最后由 gantanhao00 于 2009-10-08 09:59:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str = System.DateTime.Now.ToString("yyyy-M-d h:mm:ss"); string regex = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //日期部分 regex += @"(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //时间部分 ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$参考一下吧楼主 http://www.cnblogs.com/a409254613/archive/2008/05/06/1185273.html using System;using System.Text.RegularExpressions;class Test{ static void Main() { string strAll = @"t0=new Date().getTime();nyear=2009;nmonth=10;nday=8;nwday=5-1;nhrs=9;nmin=57;nsec=23;s=document.URL;pos=s.indexOf(""#"");fstyle=decodeURI(s.substring(pos+1,s.length));"; string year = Regex.Match(strAll, @"(?i)(?<=\bnyear\s*=\s*)\d+" ).Value; string month = Regex.Match(strAll, @"(?i)(?<=\bnmonth\s*=\s*)\d+").Value; string day = Regex.Match(strAll, @"(?i)(?<=\bnday\s*=\s*)\d+" ).Value; string hour = Regex.Match(strAll, @"(?i)(?<=\bnhrs\s*=\s*)\d+" ).Value; string minute = Regex.Match(strAll, @"(?i)(?<=\bnmin\s*=\s*)\d+" ).Value; string second = Regex.Match(strAll, @"(?i)(?<=\bnsec\s*=\s*)\d+" ).Value; //.要求str结果为:2009-10-8 9:57:23 string str = string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, day, hour, minute, second); Console.WriteLine(str); }} using System;using System.Text.RegularExpressions;class Test{ static void Main() { string strAll = @"t0=new Date().getTime();nyear=2009;nmonth=10;nday=8;nwday=5-1;nhrs=9;nmin=57;nsec=23;s=document.URL;pos=s.indexOf(""#"");fstyle=decodeURI(s.substring(pos+1,s.length));"; Regex r = new Regex(@"(?si).*?\bnyear\s*=\s*(\d+).*?\bnmonth\s*=\s*(\d+).*?\bnday\s*=\s*(\d+).*?\bnhrs\s*=\s*(\d+).*?\bnmin\s*=\s*(\d+).*?\bnsec\s*=\s*(\d+).*"); //.要求str结果为:2009-10-8 9:57:23 string str = r.Replace(strAll, "$1-$2-$3 $4:$5:$6"); Console.WriteLine(str); }} 如何使引用的.net类库在“转到定义”从“元数据”查看下隐藏具体代码? C#中怎么无法将数据库表中的int类型转化成double呢 关于数组的输出错误 C#中式怎么实现日期自动加一个月的代码 触发器中将表a中增加的行作为列名添加到表b中 visual studio team foundation 安装的问题 急! VS 2008 打的安装包,在windows 7 和 Vista 下的问题。 C# 调用迅雷问题 gdi+绘图问题,怎么避免擦除背景 我的VSTS装了为什么没有源代码管理工具 关于索引 不知道为什么继承的类不能使用有参数类的构造,为什么会报错!
regex += @"(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //时间部分
^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$
参考一下吧楼主 http://www.cnblogs.com/a409254613/archive/2008/05/06/1185273.html
using System.Text.RegularExpressions;class Test
{
static void Main()
{
string strAll = @"t0=new Date().getTime();
nyear=2009;
nmonth=10;
nday=8;
nwday=5-1;
nhrs=9;
nmin=57;
nsec=23;
s=document.URL;pos=s.indexOf(""#"");
fstyle=decodeURI(s.substring(pos+1,s.length));"; string year = Regex.Match(strAll, @"(?i)(?<=\bnyear\s*=\s*)\d+" ).Value;
string month = Regex.Match(strAll, @"(?i)(?<=\bnmonth\s*=\s*)\d+").Value;
string day = Regex.Match(strAll, @"(?i)(?<=\bnday\s*=\s*)\d+" ).Value;
string hour = Regex.Match(strAll, @"(?i)(?<=\bnhrs\s*=\s*)\d+" ).Value;
string minute = Regex.Match(strAll, @"(?i)(?<=\bnmin\s*=\s*)\d+" ).Value;
string second = Regex.Match(strAll, @"(?i)(?<=\bnsec\s*=\s*)\d+" ).Value; //.要求str结果为:2009-10-8 9:57:23
string str = string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, day, hour, minute, second);
Console.WriteLine(str);
}
}
using System.Text.RegularExpressions;class Test
{
static void Main()
{
string strAll = @"t0=new Date().getTime();
nyear=2009;
nmonth=10;
nday=8;
nwday=5-1;
nhrs=9;
nmin=57;
nsec=23;
s=document.URL;pos=s.indexOf(""#"");
fstyle=decodeURI(s.substring(pos+1,s.length));"; Regex r = new Regex(@"(?si).*?\bnyear\s*=\s*(\d+).*?\bnmonth\s*=\s*(\d+).*?\bnday\s*=\s*(\d+).*?\bnhrs\s*=\s*(\d+).*?\bnmin\s*=\s*(\d+).*?\bnsec\s*=\s*(\d+).*"); //.要求str结果为:2009-10-8 9:57:23
string str = r.Replace(strAll, "$1-$2-$3 $4:$5:$6");
Console.WriteLine(str);
}
}