I am trying to write a Regex to match the "time" (hh:mm:ss
) for example 11:20:00
, 18:02:22
or 6:00:00
.
I wrote the following but it does not work as expected. It matches when its the only thing in the string or if its the first value in the string. For example:
string timepattern = @"^([0-1]?\d|2[0-3])(?::([0-5]?\d))?(?::([0-5]?\d))?";
string value = "30.Jul.2019 This the line I want to match 15:04:09"
var returnedValue = Regex.Match(line, timepattern);
returnedValue
would yield 3
. But I want the whole time.