Regex Generator

Log Line Validator

Validate if a given string is a log line using a regular expression


Empty image or helper icon

Prompt

2020-03-12T13:34:56.123Z INFO  [org.example.Class]: This is a #simple #logline

Answer

The regular expression to validate the given log line is ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\sINFO\s\[\w+\.\w+\]:\s.*$.

Explanation:

  • ^ and $ match the start and end of the string respectively, ensuring the whole string is matched.
  • \d{4}-\d{2}-\d{2} matches the date in the format YYYY-MM-DD.
  • T matches the literal character 'T'.
  • \d{2}:\d{2}:\d{2}\.\d{3} matches the time in the format HH:MM:SS.SSS.
  • Z matches the literal character 'Z'.
  • \s matches a whitespace character.
  • INFO matches the literal string 'INFO'.
  • \[\w+\.\w+\] matches a tag in the format [org.example.Class].
  • : matches the literal character ':'.
  • \s matches a whitespace character.
  • .* matches any characters.
  • This regular expression assumes that the string only contains the given log line.

Language: Regular Expression.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This tool named "Log Line Validator" is designed to check if a given string follows a specific log line format by using a regular expression. The regular expression is ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\sINFO\s\[\w+\.\w+\]:\s.*$. It checks if the string matches the format of a log line, which includes a date, time, log level, tag, and log message. If the string matches the regular expression, it is considered a valid log line. This tool can be used to ensure that log lines are properly formatted in a system or application.