Issue
I'm trying to extract the meeting date / time from meeting invites within Gmail's subject. Below is an example of a subject for a meeting invite:
Invitation: Bob / Carol Meeting @ Tue Oct 25, 2022 11:30am - 12pm (CST) ([email protected])
What I would like to extract:
Tue Oct 25, 2022 11:30am - 12pm (CST)
I think the pattern could simply start with the space after the "@" and end with the ")". My Regex is very rusty so would appreciate any help :)
Many thanks!
Solution
Try this - it should match everything after the "@ " and up to the end of the timezone ")"
import re
string = (
'Invitation: Bob / Carol Meeting @ Tue Oct 25, 2022 11:30am - 12pm (CST) ([email protected])'
)
pattern = re.compile(r'(?<=@ )[^)]+\)')
matches = re.findall(pattern, string)
print(matches)
# => 'Tue Oct 25, 2022 11:30am - 12pm (CST)'
See here for a breakdown of the RegEx I used. Bear in mind that re.findall
returns a list of matches, which is helpful if you want to scan a long multiline string of text and get all the matches at once. If you only care about the 1st match, you can get it by index e.g. print(matches[0])
.
Answered By - JRiggles
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.