Reputation: 2614
I've got a log file with the following time stamp format:
May 02 13:27:15.722996
What regex should I use to match that? i.e. from a two hundred character line I just want to return this particular string - it's always at the beginning of the line...
Upvotes: 1
Views: 2614
Reputation: 137997
A simple pattern can be:
^\w+\s\d\d\s\d\d:\d\d:\d\d\.\d+
Not much to it, really. You can replace \d
with [0-9]
, or maybe compact it a little, but it's pretty straightforward. You may also want to make some of the digits optional, in case you don't have leading zeros (May 3 1:2:3.34
, for example):
^\w+\s\d\d?\s\d\d?:\d\d?:\d\d?\.\d+
Upvotes: 3