Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2026-01-21 14:51
Updated·2026-01-21 15:00
Flavor·PCRE2 (PHP)

/
^\[(?<ts>[\d -:]+)\] (?:\w+\.)*(?<lvl>[A-Z]+): (?<msg>[^{]*?)(?:\{"exception":(?<exception>.* (?:at (?<file>.*):(?<line>\d+))?.*)?(?<stack>\[stacktrace\].*)?\})?(?<context>\{.*\})?$
/
s
Open regex in editor

Description

Extracts the following fields from a Laravel Log print:

  • Time Stamp (Date)
  • Log Level (supports optional prefix (ie. local.DEBUG))
  • Log Message
  • Exception | Context

If an exception is detected, the file reference (file path + line number), and optional stacktrace are captured.

Submitted by Jerren