Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(Darn, Jon beat me. Oh well, you can look at the examples anyway)</p> <p>Like the other guys have said, regex is not the best tool for this job. If you are working with filepaths, take a look at <a href="http://docs.python.org/2/library/os.path.html" rel="nofollow">os.path</a>.</p> <p>As for filtering files you don't want, you can do <code>if 'thumb' not in filename: ...</code> once you have dissected the path (where <code>filename</code> is a <code>str</code>).</p> <p>And for posterity, here are my thoughts on those regex. <code>r".*(?!thumb).*"</code> does not work as because <code>.*</code> is greedy and the lookahead is given a very low priority. Take a look at this:</p> <pre><code>&gt;&gt;&gt; re.search('(.*)((?!thumb))(.*)', '/tmp/somewhere/thumb').groups() ('/tmp/somewhere/thumb', '', '') &gt;&gt;&gt; re.search('(.*?)((?!thumb))(.*)', '/tmp/somewhere/thumb').groups() ('', '', '/tmp/somewhere/thumb') &gt;&gt;&gt; re.search('(.*?)((?!thumb))(.*?)', '/tmp/somewhere/thumb').groups() ('', '', '') </code></pre> <p>The last one is quite strange...</p> <p>The other regex (<code>r"^(?!.*thumb).*"</code>) works because <code>.*</code> is inside the lookahead, so you don't have any issues with characters being stolen. You actually don't even need the <code>^</code>, depending on if you are using <code>re.match</code> or <code>re.search</code>:</p> <pre><code>&gt;&gt;&gt; re.search('((?!.*thumb))(.*)', '/tmp/somewhere/thumb').groups() ('', 'humb') &gt;&gt;&gt; re.search('^((?!.*thumb))(.*)', '/tmp/somewhere/thumb').groups() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'NoneType' object has no attribute 'groups' &gt;&gt;&gt; re.match('((?!.*thumb))(.*)', '/tmp/somewhere/thumb').groups() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: 'NoneType' object has no attribute 'groups' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload