Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!novso.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debug': 0.03; 'escape': 0.04; 'parser': 0.05; 'behave': 0.07; 'behavior.': 0.07; 'bits': 0.07; 'character,': 0.07; "shouldn't": 0.07; 'though.': 0.07; 'python': 0.08; '(it': 0.09; 'down,': 0.09; 'url.': 0.09; 'written': 0.14; 'am,': 0.14; 'broken': 0.14; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'approach,': 0.16; 'code),': 0.16; 'differently,': 0.16; 'parser,': 0.16; 'resist': 0.16; 'simplified': 0.16; 'trimming': 0.16; 'url:revision': 0.16; 'html,': 0.19; 'simpler': 0.19; 'guess': 0.19; 'header:In-Reply- To:1': 0.21; "aren't": 0.22; 'subject:problem': 0.22; "wasn't": 0.22; 'code.': 0.22; 'code': 0.24; 'match': 0.26; 'example': 0.27; "i'm": 0.27; '(not': 0.28; 'problem': 0.28; 'keeps': 0.28; 'received:209.85.214': 0.28; 'solving': 0.29; 'matches': 0.29; "python's": 0.29; 'instead': 0.29; 'code,': 0.29; 'putting': 0.30; 'html.': 0.30; 'sun,': 0.30; 'whitespace': 0.30; 'it.': 0.31; 'supposed': 0.31; 'specifically': 0.31; 'andrew': 0.32; 'steven': 0.32; 'to:addr:python-list': 0.33; 'rather': 0.34; 'characters': 0.34; 'header:User-Agent:1': 0.35; "d'aprano": 0.35; 'message- id:@gmail.com': 0.36; 'probably': 0.36; 'uses': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'put': 0.37; 'think': 0.38; 'problem.': 0.38; 'but': 0.38; 'purposes': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'sometimes': 0.39; 'should': 0.39; 'received:209': 0.39; 'attempt': 0.39; 'containing': 0.39; 'goes': 0.39; 'rest': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'received:192.168.1': 0.40; 'almost': 0.60; 'more': 0.60; 'your': 0.60; 'piece': 0.63; 'show': 0.66; 'noise': 0.67; 'dealing': 0.69; 'relevant': 0.69; 'apologize': 0.72; 'endeavor.': 0.84; 'irrelevant': 0.84; 'match?': 0.84; 'rip': 0.84; 'give.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=OHlTPw+2fSIQnBM0g9XoN4vKqcNTNyw+Zw0gfQgyoF4=; b=OraWBMG0xIeoAKoQaRz2W5xCz5Uxt8b+iDwRSlEn0ttDy+r13GbJC9SIFJ4Bd4GRu9 9FiLgUXdBTxSO0GPyQaAaYk8HLS6VKocAwfQX85Rj0wzVwBRxu40TAyHDbCqx7412cB1 j1V3Hv1z+0TUvqIfzd5gesu240sGz1/A2dgNE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=cMWJqkBiHWV/bFuFgOejYgpi1c6fZlFZvRp8XqhYAxr7suzKOY6kFiUdwRsWSfJuUj XLSacpeDW0c9nyNKc5YIavnCn6FtqgHLt/4CccLk/OyBKIpnueREuNjyvey6hwBi1F4d 0ckkKNHdkIwdHgrAqXW8jI+a8R1rdZGVZKrkU= Date: Sun, 29 May 2011 08:41:16 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Weird problem matching with REs References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306676483 news.xs4all.nl 49047 [::ffff:82.94.164.166]:48927 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6536 On 2011.05.29 08:09 AM, Steven D'Aprano wrote: > On Sun, 29 May 2011 06:45:30 -0500, Andrew Berg wrote: > > > I have an RE that should work (it even works in Kodos [1], but not in my > > code), but it keeps failing to match characters after a newline. > > Not all regexes are the same. Different regex engines accept different > symbols, and sometimes behave differently, or have different default > behavior. That your regex works in Kodos but not Python might mean you're > writing a Kodus regex instead of a Python regex. Kodos is written in Python and uses Python's regex engine. In fact, it is specifically intended to debug Python regexes. > Firstly, most of the code you show is irrelevant to the problem. Please > simplify it to the shortest, most simple example you can give. That would > be a simplified piece of text (not the entire web page!), the regex, and > the failed attempt to use it. The rest of your code is just noise for the > purposes of solving this problem. I wasn't sure how much would be relevant since it could've been a problem with other code. I do apologize for not putting more effort into trimming it down, though. > Secondly, you probably should use a proper HTML parser, rather than a > regex. Resist the temptation to use regexes to rip out bits of text from > HTML, it almost always goes wrong eventually. I find this a much simpler approach, especially since I'm dealing with broken HTML. I guess I don't see how the effort put into learning a parser and adding the extra code to use it pays off in this particular endeavor. > > I was able to make a regex that matches in my code, but it shouldn't: > > http://x264.nl/x264/64bit/8bit_depth/revision.\n{1,3}[0-9]{4}.\n{1,3}/ > x264.\n{1,3}.\n{1,3}.exe > > What makes you think it shouldn't match? AFAIK, dots aren't supposed to match carriage returns or any other whitespace characters. > By the way, you probably should escape the dots, otherwise it will match > strings containing any arbitrary character, rather than *just* dots: You're right; I overlooked the dots in the URL.