datetime - Regex to pick out correct time in powershell depending on what is next to it -


i using powershell regex try , extract following time line below "01:42:35". want ignore time "02:42:35" unsure of how it.

2013-07-04 02:42:35 alert 172.172.19.9 jul 4 01:42:35 ...

currently using time regex: $time_regex = "(\d+):(\d+):(\d+)" how can adapt above specification?

note: time trying not @ end of line , second time has date next in format "jul 4 " whereas first time has date next in format "2013-07-04"

thanks

$time_regex = "(?<=\w+ \d+ )(\d+):(\d+):(\d+)" 

will match time string that's preceded alphanumeric "word" , number.


Comments