title: python regex: extract list elements, each of which matches multiple patterns
body: <p>I am totally new to python. Suppose I have a list as follows.</p>
  
  <pre><code> somelist =  
  ['AAAA  1234   SD OXD',
   'AAAB  2342   DF BDD',
   'ERTE  3454   RE DFD',
   'GWED  1234   SD TCD',
   'AAAA  2353   SD MKX',
   'VERD  1234   IO ERT']
  </code></pre>
  
  <p>And I would like to extract elements that match both '1234' at position 7-10 and 'SD' at position 14-15 (just an example, could be any combination of positions, with anything in between). The result would be as follows. </p>
  
  <pre><code>['AAAA  1234   SD OXD', 'GWED  1234   SD TCD']
  </code></pre>
  
  <p>What I am doing now is to nest a filter() function inside another.</p>
  
  <pre><code>x = filter(lambda x: re.match('1234', x[6:10]), filter(lambda r: re.match('SD', r[13:15]), somelist))
  </code></pre>
  
  <p>This works but looks rather chunky and dumb. Can someone help get a solution that's more elegant and faster? The list could contain millions of elements (from lines in a file). </p>
  
  <p>There are many discussions about searching/matching any of the patterns/regexes (<strong>match A OR B</strong>). This is to <strong>match A AND B</strong>, which must be as common a problem as the <strong>OR</strong> problem. Apparently it's gonna get messy if I want to <strong>match A and B and C and ...</strong> at different locations.</p>
  
  <blockquote>
    <p><strong>Update:</strong>  Thank you all. My original question was probably not clear enough. It's basically an 'element must match ALL of several patterns at
    given positions' question. </p>
    
    <p>Inspired by <strong>Kcorlidy</strong>'s response particularly, I gave it a few quick
    shots and these worked (and <code>.</code> indeed means <code>'anything'</code>, except
    <code>\n</code> according to the manual): </p>
    
    <p>To match '1234' and 'SD' at said positions:</p>
    
    <p><code>filter(lambda x: re.search(r'.{6}1234.{3}SD', x), somelist)</code> </p>
    
    <p>To match 'AAAA' and 'SD' at 0:4 and 13:15, respectively:</p>
    
    <p><code>filter(lambda x: re.search(r'.{0}1234.{9}SD', x), somelist)</code></p>
    
    <p>The take-home message is the <strong>numbers in the curly parentheses</strong>
    seem to mean <strong>'distance' (number of characters) from the end of the
    previous pattern</strong> ('distance' from the beginning, i.e. ^, if it's
    for the first pattern), not the start position of concerned pattern.
    That's the whole key point. Simple stuff - that's probably why more
    are interested in the <strong>match A or B</strong> rather than this <strong>match A and
    B</strong> problem.</p>
  </blockquote>