Pattern matching in Python regexp
Question: How can I use regexp in python to extract the date from an html `<div>` tags.
Html is something like this

`<div><strong>Date:<\/strong> Monday April 6, 2015 at 4:41PM <div>`

I need to get date in "yyyy-dd-mm hh:mm" format. Output for this should be
"2015-04-06 16:41"


Answer: Instead of approaching the problem with regular expressions (see [RegEx match
open tags except XHTML self-contained
tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-
xhtml-self-contained-tags)), I would use an _HTML Parser_ ,
[`BeautifulSoup`](http://www.crummy.com/software/BeautifulSoup/bs4/doc/), and
[`dateutil`](https://labix.org/python-dateutil) for extracting the date. After
extracting the date, use
[`strftime()`](https://docs.python.org/2/library/datetime.html#datetime.datetime.strptime)
to dump it into a string in the desired format:

    
    
    >>> from bs4 import BeautifulSoup
    >>> from dateutil import parse
    >>> s = "<div><strong>Date:</strong> Monday April 6, 2015 at 4:41PM <div>"
    >>> text = soup.find('div').text
    >>> parse(text, fuzzy=True).strftime("%Y-%d-%m %H:%M")
    '2015-06-04 16:41'
    

