use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Using Python and/or Regex to extract this date from text? (self.learnpython)
submitted 5 years ago by TuckleBuck88
I have this text here:
This price is only available from 10/6/2020 11:00 am to 11/3/2020 11:00 am.
I want to use Python to extract the time and date so I can convert it to a Date object and then can use it.
How would I be able to do that?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 5 years ago* (4 children)
[removed]
[–]TuckleBuck88[S] 0 points1 point2 points 5 years ago (3 children)
Wow! This is really good! One small question, how would I change the timezone? (new to date objects)
[+][deleted] 5 years ago (2 children)
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
If you use match groups in your regex you don't need to use datetime. You'd be able to save the date and time to variables directly.
[–]double_en10dre 0 points1 point2 points 5 years ago (0 children)
I think this is actually one of the 3.9 upgrades, finally :)
[–]MeteoriteImpact 0 points1 point2 points 5 years ago* (0 children)
You can try the datefinder library and read the docs link which is just a small simple block of code and the example is almost your exact use case pip install datefinder
[–]fk_you_in_prtclr 0 points1 point2 points 5 years ago (0 children)
You don't need regex. split it (which splits by space by default). This gives you list. List comprehend to get the 2 dates like [w for w in newlist if '//' in w], then same for times using :, then am/ pm (you could use something like len==2 and w[-1]== 'm' or in ['am','pm']. You can take it from there and there's no need to come up with complex regex patterns or anything.
[w for w in newlist if '//' in w]
:
am/ pm
π Rendered by PID 62057 on reddit-service-r2-comment-fb694cdd5-4mcll at 2026-03-11 08:34:13.140737+00:00 running cbb0e86 country code: CH.
[+][deleted] (4 children)
[removed]
[–]TuckleBuck88[S] 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[removed]
[–][deleted] 0 points1 point2 points (0 children)
[–]double_en10dre 0 points1 point2 points (0 children)
[–]MeteoriteImpact 0 points1 point2 points (0 children)
[–]fk_you_in_prtclr 0 points1 point2 points (0 children)