Return to Snippet

Revision: 1477
at October 10, 2006 19:37 by roberocity


Initial Code
Complete Expression for a standard stats log

^(?<Date>(?<Year>\d{4}|\d{2})-(?<Month>\d{1,2})-(?<Day>\d{1,2}))\s(?<Time>(?<Hour>\d{1,2}):(?<Minute>\d{1,2}):(?<Second>\d{1,2}))\s(?<ClientIP>(?<A>\d{1,3})\.(?<B>\d{1,3})\.(?<C>\d{1,3})\.(?<D>\d{1,3}))\s(?<Username>[\w-]*)\s(?<Method>\w*)\s(?<URI>[\w/-_\.+]*)\s(?<StatusCode>\d{3})\s(?<Bytes>\d*)\s(?<Version>[\w/-_\.+]*)\s(?<UserAgent>[\w/-_\.+;()]*|-)\s(?<Referer>[\w\.-_://]*|-)

Complete Expression for a standard stats log with URI broken into prefix and extension

^(?<Date>(?<Year>\d{4}|\d{2})-(?<Month>\d{1,2})-(?<Day>\d{1,2}))\s(?<Time>(?<Hour>\d{1,2}):(?<Minute>\d{1,2}):(?<Second>\d{1,2}))\s(?<ClientIP>(?<A>\d{1,3})\.(?<B>\d{1,3})\.(?<C>\d{1,3})\.(?<D>\d{1,3}))\s(?<Username>[\w-]*)\s(?<Method>\w*)\s(?<URI>(?<Prefix>[\w/-_\.+]*)\.(?<Ext>\w{0,8}))\s(?<StatusCode>\d{3})\s(?<Bytes>\d*)\s(?<Version>[\w/-_\.+]*)\s(?<UserAgent>[\w/-_\.+;()]*|-)\s(?<Referer>[\w\.-_://]*|-)


Pieces:


Date
(?<Date>(?<Year>\d{4}|\d{2})-(?<Month>\d{1,2})-(?<Day>\d{1,2}))

Time
(?<Time>(?<Hour>\d{1,2}):(?<Minute>\d{1,2}):(?<Second>\d{1,2}))

IP Address
(?<ClientIP>(?<A>\d{1,3})\.(?<B>\d{1,3})\.(?<C>\d{1,3})\.(?<D>\d{1,3}))

UserName
(?<Username>[\w-]*)


Method
(?<Method>\w*)

URI
(?<URI>[\w/-_\.+]*)
(?<URI>(?<Prefix>[\w/-_\.+]*)\.(?<Ext>\w{0,8}))

StatusCode
(?<StatusCode>\d{3})

Bytes
(?<Bytes>\d*)


Version
(?<Version>[\w/-_\.+]*)

UserAgent
(?<UserAgent>[\w/-_\.+;()]*|-)

Referrer
(?<Referer>[\w\.-_://]*|-)

Initial URL

                                

Initial Description

                                

Initial Title
RegEx for parsing log files

Initial Tags
regex

Initial Language
Other