c# - Why doesn't this Regex match the date part of the input? -
i attempting take object's text value, obtain information through regex, , type output notepad. below code, , object references correct. have been able type other information notepad, including full text of object regex trying extract, assume there problem match.groups[1].value, can't seem figure out.
string pattern= @".*[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\s(a|p)m$"; string input = repo.changedbydate.element.getattributevaluetext("text"); match match = regex.match(input, pattern); string dateregex = match.groups[1].value; notepad.textbox.presskeys(dateregex);
edit: apologies, posted , without more pertinent information.
the above code meant match date/time portion of string original text is:
current date , time is: 8/7/2013 12:15:02 pm
so want extract 8/7/2013 12:15:02 pm
regex assigned pattern
.
as of now, no output being placed notepad. however, if change code following:
string input = repo.changedbydate.element.getattributevaluetext("text"); notepad.textbox.presskeys(input);
my output in notepad current date , time is: 8/7/2013 12:15:02 pm
the .*
in regex match start of string. can exclude entirely, , group 0 (all content matched regex). note should checking success before accessing groups.
string pattern= @"[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\s[ap]m"; match match = regex.match(input, pattern); if (match.success) { string dateregex = match.groups[0].value; notepad.textbox.presskeys(dateregex); }
Comments
Post a Comment