title: AttributeError: 'NoneType' object has no attribute 'groups' - re.search
body: <p>I am trying to parse first 3 elements of a row in a CSV file. The following is the data in the CSV file:</p>
  
  <pre><code>{::[name]str1_str2_str3[0]},1,U0.00 - Sensor1 Not Ready\nTry Again,1,0,12
  </code></pre>
  
  <p>I want to parse the value 0 or 1 within the [ ] from the first element. Then the value in second element. From third element, I want to parse the substring "Sensor1 Not Ready", then convert it to UPPERCASE and replace the space with underscore (eg - SENSOR1_NOT_READY). And then print the string in a new column.</p>
  
  <p>As suggested in one of my previous <a href="https://stackoverflow.com/questions/46934884/parsing-a-csv-file-with-column-data-in-python">question</a>,</p>
  
  <p>I did the following -</p>
  
  <pre><code>import csv
  import re
  
  with open('filename.csv', 'rb') as csvfile:
      reader = csv.reader(csvfile)
      for row in reader:
          tag_name = row[0] # Column A
          bit_num = row[1] # Column B
          error_name = row[2] # Column C
  
          term0 = '\[(\d)\].*'
          term1 = '(\d+)'
          term2 = '.*-\s([\w\s]+)\\n'
  
          capture0 = list(re.search(term0, tag_name).groups())
          capture1 = list(re.search(term1, bit_num).groups())
          capture2 = list(re.search(term2, error_name).groups())
  </code></pre>
  
  <p>When I tried to print capture2, I got the following error -</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'groups'
  </code></pre>
  
  <p>Can somebody explain what it means and what modifications I need to make?</p>