日期:2014-05-18  浏览次数:20649 次

2012年6月--怎么用正则取年月数
如题,对正则不是很熟,搞了半天都没搞出来,请求指教

------解决方案--------------------
C# code

            string source = "2012年6月";
            Regex reg = new Regex(@"(?<year>\d{4}).*(?<month>\d{1,2}).*");
            Match mm = reg.Match(source);
            MessageBox.Show(mm.Groups["year"].Value);
            MessageBox.Show(mm.Groups["month"].Value);

------解决方案--------------------
探讨

引用:
引用:

格式不会变,格式为2012年6月,谢谢楼上

那根本不用正则,用string.Substring()截取就行了啊

string source = "2012年6月";
string source1=source.Substring(0,4);
string source1=source.Substring(5,1);

……