I have a line from a text file and I'm trying to create a regular expression to match. This is the line of text.
2015-01-07 Wed Jan 07 11:03:43.390 Some text here..
My regular expression to match is as follows:
(?<date>(?<year>(?:\d{4}|\d{2})-(?<month>\d{1,2})-(?<day>\d{1,2})))\s(?<txtEntry1>.*)\s(?<txtEntry2>.*)\s(?<txtEntry3>.*)\s(?<time>(?<hour>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2}):(?<milli>\d{0,3}))\s(?<txtEntry4>.*)\s(?<txtEntry5>.*))
It doesn't match. I'm not concerned about the 'worded' date Wed Jan 07 so I have just left it as a text entry, rather than match it yo to dd/mm/yy. I have been trying to figure it our but with no success. Can anyone see where I have gone wrong?
\s(?<txtEntry1>.*)\s(?<txtEntry2>.*)\s(?<txtEntry3>.*)is a terrible idea, since it cause a lot of unnecessary backtracking. Consider at least using\S*in place of.*- if you know the number of non-space tokens before hand. For the trailing\s(?<txtEntry4>.*)\s(?<txtEntry5>.*), I don't know why you need 2 of them, but if you only need the whole text, you can just use one of them\s(?<txtEntry4>.*)to capture the rest of the string.