BytePane

Log File Timestamp Regex Pattern

Matches ISO 8601 timestamps commonly found in application and system log files.

System Administration
Intermediate
Difficulty
Universal
Language
none
Flags
// Regular Expression
/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?/

Live Regex Tester

Pattern Breakdown

^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?
Character class [ ]
Group ( )
Quantifier { }
Anchor ^ $
Repetition * + ?
Escape \
Alternation |
Any char .

Code Examples

JavaScript

const regex = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?/;
const test = "2024-03-15T14:30:00.123Z";
console.log(regex.test(test)); // true

// Extract matches
const matches = test.match(regex);
console.log(matches);

Python

import re

pattern = r'^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?'
test = "2024-03-15T14:30:00.123Z"
match = re.search(pattern, test)
print(match)  # Found!

Go

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?`)
    fmt.Println(re.MatchString("2024-03-15T14:30:00.123Z")) // true
}

Common Use Cases

Log parsingmonitoringtime-series analysis

Match Examples

InputResult
2024-03-15T14:30:00.123ZMatch
March 15, 2024No Match

About the Log File Timestamp Regex

Matches ISO 8601 timestamps commonly found in application and system log files.

Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The log file timestamp pattern is classified as intermediate difficulty in the system administration category. It works in all major programming languages.

When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.

Need More Regex Patterns?

Browse our complete library of 100+ regex patterns with interactive testers.

Frequently Asked Questions

What is the Log File Timestamp regex pattern?

Matches ISO 8601 timestamps commonly found in application and system log files.

How do I use the Log File Timestamp regex?

Use the pattern /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?/ in your code. In JavaScript: new RegExp('^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:?\d{2})?', ''). Test it above with your own input.

What does this Log File Timestamp regex match?

This pattern matches: "2024-03-15T14:30:00.123Z". It does NOT match: "March 15, 2024". Log parsing, monitoring, time-series analysis.

Is the Log File Timestamp regex beginner-friendly?

This pattern is rated Intermediate. It uses some advanced features like character classes and quantifiers.

What languages support the Log File Timestamp regex?

This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.

Can I modify the Log File Timestamp regex for my use case?

Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.