Saturday, November 25, 2023

Python Date search regex

def contains_date(line):

    # Define the regular expression pattern

    date_pattern = r'\b\d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2}\.\d{3}\b'


    # Check if the pattern is present in the line

    return bool(re.search(date_pattern, line))

line1 = "Some text 23-Nov-2023 05:56:30.738 more text"


def contains_date(line):

    # Define the regular expression pattern

    date_pattern = r'\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\]'


    # Check if the pattern is present in the line

    return bool(re.search(date_pattern, line))

line1 = "Some text [2023-11-25T08:00:40.914Z] more text"



No comments:

Post a Comment