String src = "2012-2-14";
Match m = Regex.Match(src, @"^(?<yyyy>\d{4})[\s@|:/.-]+(?<mm>\d{1,2})[\s@|:/.-]+(?<dd>\d{1,2})$");
if (m.Success)
{
Response.Write(m.Result("${yyyy}"));
Response.Write("<br/>");
Response.Write(m.Result("${mm}"));
Response.Write("<br/>");
Response.Write(m.Result("${dd}"));
Response.Write("<br/>");
Response.Write("<br/>");
Response.Write(m.Groups["yyyy"].Value);
Response.Write("<br/>");
Response.Write(m.Groups["mm"].Value);
Response.Write("<br/>");
Response.Write(m.Groups["dd"].Value);
Response.Write("<br/>");
Response.Write("<br/>");
foreach (Group g in m.Groups)
{
Response.Write(String.Format("{0} : {1}<br/>", g.Index, g.Value));
foreach (Capture c in g.Captures)
{
Response.Write(String.Format("{0} : {1}<br/>", c.Index, c.Value));
}
}
}
정규식을 이용한 날짜 체크 예제
|
2012.02.10 10:55:21
|
2012.02.10 10:55:21
|
297
|
Aiden
Total of Attached file
0.00 Bytes of 0 files
2012.07.22
2012.02.10
2008.12.27
2008.12.20
2008.04.09
2004.05.23
2003.10.21