<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'match extensions with regular expresion' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'match extensions with regular expresion' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:54:02 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:54:02 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>match extensions with regular expresion</title>
      <link>http://www.programmersheaven.com/mb/python/413266/413266/match-extensions-with-regular-expresion/</link>
      <description>hello to all!&lt;br /&gt;
&lt;br /&gt;
I'm new to python , worked with regexp in javascript only, and I'm stuck with one little problem, I want to know if File has extension: .zip .7z .gz .tar ...(only Compressed Files).&lt;br /&gt;
&lt;br /&gt;
But if it's .rar, it must not be xxx.partN.rar ('N' is a number and 'xxx' can be anything) UNLESS 'N' is '1' or '01' '001' etc.&lt;br /&gt;
&lt;br /&gt;
Any help will be greatly appreciated.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/413266/413266/match-extensions-with-regular-expresion/</guid>
      <pubDate>Mon, 08 Feb 2010 15:48:42 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: match extensions with regular expresion</title>
      <link>http://www.programmersheaven.com/mb/python/413266/413687/re-match-extensions-with-regular-expresion/#413687</link>
      <description>: hello to all!&lt;br /&gt;
: &lt;br /&gt;
: I'm new to python , worked with regexp in javascript only, and I'm &lt;br /&gt;
: stuck with one little problem, I want to know if File has extension: &lt;br /&gt;
: .zip .7z .gz .tar ...(only Compressed Files).&lt;br /&gt;
: &lt;br /&gt;
: But if it's .rar, it must not be xxx.partN.rar ('N' is a number and &lt;br /&gt;
: 'xxx' can be anything) UNLESS 'N' is '1' or '01' '001' etc.&lt;br /&gt;
: &lt;br /&gt;
: Any help will be greatly appreciated.&lt;br /&gt;
: &lt;br /&gt;
&lt;pre class="sourcecode"&gt;
import re
rar = re.compile(".+\.part[^(0*1)]\.rar") #invalid rar's
ext_list = ['zip','7z', 'gz', 'tar', 'rar'] #and whatever else

def foo(n):
  if n[n.rfind('.') + 1:] in ext_list: 
    if not n[-3:] == 'rar':
      return True                #valid not rar file
    elif rar.match(n):
      return False               #invalid rar file
    return True                  #valid rar file
  return False                   #not in ext_list
[\code]

&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/413266/413687/re-match-extensions-with-regular-expresion/#413687</guid>
      <pubDate>Fri, 19 Feb 2010 16:59:43 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
