found this datetime regular expression in RegExLib site -> http://regexlib.com/REDetails.aspx?regexp_id=361
string pattern = @"^(((((0[13578])|([13578])|(1[02]))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(3[01])))|((([469])|(11))[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9])|(30)))|((02|2)[\-\/\s]?((0[1-9])|([1-9])|([1-2][0-9]))))[\-\/\s]?\d{4})(\s(((0[1-9])|([1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$";
var match = Regex.Match("test 123 11/30/2003 10:12:24 am", pattern, RegexOptions.IgnoreCase);
The above works if the string is exact (it doesn’t find it with the test 123 in it), but how do I make it where it finds the date embedded in a string somewhere (as shown)?
Your regular expression matches beginning (
^) and end ($) of string. If you remove corresponding elements from the expression it will fid date anywhere in the string.And here is the link to all regEx characters.