Mar-04-2024, 11:55 PM
(This post was last modified: Mar-04-2024, 11:55 PM by deanhystad.)
If you want to be really picky.
r"" makes the pattern a raw string. Don't have to worry about escape sequences.
\s* matches any number of whitespace characters.
() creates groups. This pattern has a group for the "Start Time...PM" part, the date part and the time part.
Start Time matches Start Time.
{1,2} matches one or two spaces.
\d{1,2} matches 1 or 2 digits.
/ matches /.
: matches :.
[AP]M matches AM or PM.
\s*$ matches whitespace up to the end of the line.
with open("test.txt", "r") as file: for line in file: result = re.match(r"\s*(Start Time {1,2}(\d{1,2}/\d{1,2}/\d{4}) (\d{1,2}:\d{1,2}:\d{1,2} [AP]M))\s*$", line) if result: print(result.groups())match() forces pattern to start at the start of line.
r"" makes the pattern a raw string. Don't have to worry about escape sequences.
\s* matches any number of whitespace characters.
() creates groups. This pattern has a group for the "Start Time...PM" part, the date part and the time part.
Start Time matches Start Time.
{1,2} matches one or two spaces.
\d{1,2} matches 1 or 2 digits.
/ matches /.
: matches :.
[AP]M matches AM or PM.
\s*$ matches whitespace up to the end of the line.