title: python regex prevent nonetype error
body: <p>I have code below that searches for a pattern and assigns the pattern to a variable <code>num</code> if the pattern exists. </p>
  
  <pre><code>for row1 in cursor1:
      try:
          m = re.search(r"^[0-9]+(?=\s)", row1[0])
          num = m.group()
      except Exception as e:
          pass
  </code></pre>
  
  <p>I then use the <code>num</code> variable in the code below:</p>
  
  <pre><code>z1=(item for item in numlist if item[6]==num and harversine.myhaversine(custx,custy,item[2],item[3])&lt;150)
  </code></pre>
  
  <p>I would like to eliminate the num variable and compare text that matches the regex directly to <code>item[6]</code> as in <code>if item[6]==re.search(r"^[0-9]+(?=\s)",row1[0]).group()</code> But of course this will give me an error for the rows that don't have the pattern. How do I achieve what I am trying to do without getting the <code>nonetype has no attribute group()</code> error? 
  PS: The overall code not shown here loops through rows, creates tuples and assigns necessary values based on fulfillment of the if statement. I want to change the regex matching part shown in the code for better performance because not all rows use the <code>num</code> variable. I want the regex to be run only for the rows that use this variable.</p>