Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@crazytera crazytera commented May 24, 2020

❤️

@PaulGatille

This comment has been minimized.

Copy link

@PaulGatille PaulGatille commented May 5, 2021

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

@miticojo

This comment has been minimized.

Copy link
Owner Author

@miticojo 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

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