Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33939

Re: Regular expression for different date formats in Python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'beginner': 0.05; 'remaining': 0.07; 'python': 0.09; 'fetch': 0.09; 'files:': 0.09; 'robust': 0.09; 'dec': 0.15; 'dirs,': 0.16; 'headings': 0.16; 'soup': 0.16; 'subject:Regular': 0.16; 'subject:expression': 0.16; 'developers,': 0.16; 'are:': 0.20; 'import': 0.21; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'in.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.27; "doesn't": 0.28; 'url:mailman': 0.29; 'folder': 0.30; 'code': 0.31; 'url:python': 0.32; 'received:209.85.160.46': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'code:': 0.33; 'hi,': 0.33; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'formats': 0.35; 'nov': 0.35; 'path': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'url:org': 0.36; 'display': 0.36; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'your': 0.60; 'different': 0.63; 'information': 0.63; 'here': 0.65; 'walking': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=49R5dj4rf5oemjaxEtudYa9MY5gKC8x41n2iWY6H3ck=; b=vFg53XqgfWgv4TH/PucIKp+xN66IG0f4IeCHLH7tkUBnnex7WlmNJnYMVPjH8e6TjL WNLbFDUJkxn8uUelTzF5FBRIDkE3JXtDX6XvmrMXuMU1JVMTyZxX5lteVG2p7mmDOHDJ 43yaFFA8NfUUVIAPjPUxnGcSF8Le/Uf7ZtY3hrh802hEodmotZ3WLW4U3dEQ5RaJc9hE mQkCXjIwuT8mCC3jKQ08/xT6gajCYRAT+TXtH62qLBGa54rcfUtQYh7YcGjcNmxI4Vlk 9ozsMzf2qV/u+lwPLT7IN72/x506rREiwJMiHWuEHnioN1Cp7cmY4sn5VbVFeiXSDXxc 3a1A==
MIME-Version 1.0
In-Reply-To <804a4170-a317-482c-8eca-e76027a0ee85@googlegroups.com>
References <804a4170-a317-482c-8eca-e76027a0ee85@googlegroups.com>
Date Mon, 26 Nov 2012 17:30:17 +0100
Subject Re: Regular expression for different date formats in Python
From Vlastimil Brom <vlastimil.brom@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.291.1353947420.29569.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353947420 news.xs4all.nl 6919 [2001:888:2000:d::a6]:41311
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33939

Show key headers only | View raw


2012/11/26  <undesputed.hackerz@gmail.com>:
> Hello Developers,
>
> I am a beginner in python and need help with writing a regular expression for date and time to be fetched from some html documents. In the following code I am walking through the html files in a folder called event and printing the headings with h1 tag using beautifulsoup. These html pages also contains different formats of date and time. I want to fetch and display this information as well. Different formats of date in these html documents are:
>
> 21 - 27 Nov 2012
> 1 Dec 2012
> 30 Nov - 2 Dec 2012
> 26 Nov 2012
>
> Can someone help me out with fetching these formats from these html documents ?
> Here is my code for walking through the files and fetching h1 from those html files:
>
>
> Code:
>
>
>     import re
>     import os
>     from bs4 import BeautifulSoup
>
>     for subdir, dirs, files in os.walk("/home/himanshu/event/"):
>         for fle in files:
>             path = os.path.join(subdir, fle)
>             soup = BeautifulSoup(open(path))
>
>             print (soup.h1.string)
>
>             #Date and Time detection
>
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
the following pattern seems to match all of your examples,

(\d{1,2} )?(Nov|Dec)?( ?- )?(\d{1,2}) (Nov|Dec) (\d{4})

however, it doesn't look like very robust - of course, you have to add
the remaining months' abbreviations and check on the (parts of the)
HTML documents, you are interested in.

hth,
   vbr

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Regular expression for different date formats in Python undesputed.hackerz@gmail.com - 2012-11-26 05:15 -0800
  Re: Regular expression for different date formats in Python Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-11-26 17:30 +0100
  Re: Regular expression for different date formats in Python Michael Torrie <torriem@gmail.com> - 2012-11-26 09:05 -0700
    Re: Regular expression for different date formats in Python Miki Tebeka <miki.tebeka@gmail.com> - 2012-11-26 13:57 -0800
    Re: Regular expression for different date formats in Python Miki Tebeka <miki.tebeka@gmail.com> - 2012-11-26 13:57 -0800

csiph-web