Вот мои ревизии, с комментариями.В целом, вам лучше делать меньше предположений о том, что будут содержать поля.Здесь я использую \S
, что означает «все, кроме пробелов».Кроме того, \s+
будет соответствовать некоторому пробелу, будь то один символ или более.
(<?month>\S+) #
\s+ # added + because single digit dates might have additional spaces
(<?date>[0-9]{1,2}) # changed {2}? to {1,2} because you might have one or two digits
\s+ #
(<?time>[0-9]+:[0-9]+:[0-9]+) #
\s+ #
(<?hostname>\S+) # anything which isn't whitespace
\s+ #
(<?daemon>\S+) # just in case your daemon has a digit or lower case in its name
(<?pid>\[[0-9]+\]) #
: #
\s+ #
\((<?user>\S+)\) # your username might have digits in it; don't capture the brackets
\s+ #
CMD #
\s+ #
\((<?command>.*)\) # capture the command, not the brackets
\s* # in case of trailing space
$ # match end of string