Skip to content

Instantly share code, notes, and snippets.

@miticojo
Created September 3, 2016 08:32
Show Gist options
  • Save miticojo/b16bb13e78572c2d2fac82d9516d5c32 to your computer and use it in GitHub Desktop.
Save miticojo/b16bb13e78572c2d2fac82d9516d5c32 to your computer and use it in GitHub Desktop.
Regex for SYSLOG format RFC3164 and RFC5424
// RFC3164 https://www.ietf.org/rfc/rfc3164.txt (obsolete)
var regex_rfc3164 = /([A-Z][a-z][a-z]\s{1,2}\d{1,2}\s\d{2}[:]\d{2}[:]\d{2})\s([\w][\w\d\.@-]*)\s(.*)$/;
// RFC5424 https://www.ietf.org/rfc/rfc3164.txt
var regex_rfc5424 = /(?:(\d{4}[-]\d{2}[-]\d{2}[T]\d{2}[:]\d{2}[:]\d{2}(?:\.\d{1,6})?(?:[+-]\d{2}[:]\d{2}|Z)?)|-)\s(?:([\w][\w\d\.@-]*)|-)\s(.*)$/;
// valid string for regex test
var msg_rfc3164 = "<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8";
var msg_rfc5424 = "<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8";
@crazytera
Copy link

❤️

@PaulGatille
Copy link

thank you sir, you saved me a lot of time !

@miticojo
Copy link
Author

miticojo commented May 6, 2021

thank you sir, you saved me a lot of time !

great! I'm really happy to know ... thanks for sharing your feedback

@Pascuccii
Copy link

God bless you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment