Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.078 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'python:': 0.05; 'parsing': 0.09; 'to:addr:comp.lang.python': 0.09; 'exception': 0.12; 'res': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'url:lxml': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'skip:[ 20': 0.19; 'thanks,': 0.19; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'extract': 0.24; 'cc:addr:gmail.com': 0.28; 'script': 0.28; 'expressions': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'chris': 0.30; '(as': 0.31; 'specified': 0.31; 'subject:?': 0.31; 'tue,': 0.32; 'sort': 0.33; 'received:209.85.212': 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'anything': 0.34; 'subject:What': 0.34; 'something': 0.35; 'regular': 0.35; 'cc:2**1': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'received:209.85': 0.38; 'allows': 0.38; 'first.': 0.39; 'received:209': 0.39; 'point': 0.40; "you'll": 0.61; 'john': 0.61; 'march': 0.61; 'forward': 0.63; 'website': 0.65; 'subject:best': 0.67; 'today': 0.70; 'encountered': 0.73; 'news,': 0.73; 'song': 0.73; 'subject:this': 0.74; 'subject:write': 0.84; 'received:209.85.212.56': 0.91; 'received:mail- vw0-f56.google.com': 0.91 Received-SPF: pass (google.com: domain of johnjsal@gmail.com designates 10.236.186.4 as permitted sender) client-ip=10.236.186.4; Authentication-Results: mr.google.com; spf=pass (google.com: domain of johnjsal@gmail.com designates 10.236.186.4 as permitted sender) smtp.mail=johnjsal@gmail.com Newsgroups: comp.lang.python Date: Tue, 6 Mar 2012 15:02:42 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.30.237.113; posting-account=Wdz3OgoAAACumWTKfPjpOEJc3twpMp_1 References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: What's the best way to write this regular expression? From: John Salerno To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, John Salerno X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331074966 news.xs4all.nl 6904 [2001:888:2000:d::a6]:57796 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21281 On Tuesday, March 6, 2012 4:52:10 PM UTC-6, Chris Rebert wrote: > On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > > I sort of have to work with what the website gives me (as you'll see be= low), but today I encountered an exception to my RE. Let me just give all t= he specific information first. The point of my script is to go to the speci= fied URL and extract song information from it. > > > > This is my RE: > > > > song_pattern =3D re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.= *?).*?(.*?)', re.DOTALL) >=20 > I would advise against using regular expressions to "parse" HTML: > http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-x= html-self-contained-tags >=20 > lxml is a popular choice for parsing HTML in Python: http://lxml.de >=20 > Cheers, > Chris Thanks, that was an interesting read :) Anything that allows me NOT to use REs is welcome news, so I look forward t= o learning about something new! :)