使用group(1)从正则表达式转换为字符串不起作用

我有以下公式,旨在将最终数据帧的格式从regexp转换为string:

import re 
dataframe = pd.DataFrame(columns=('State','RegionName'))
with open('/Users/name/Desktop/university_towns.txt',"r") as f_in:
     lines = f_in.readline()
     i = 0 
     for line in lines: 
          if '[edit]' in line:
              states = re.search(r'^([^(\[]+)', line).group(1)
          else:
              countries = re.search(r'^([^(\[]+)', line).group(1)
              dataframe.loc[i] = [states,countries]
              i += 1 

但是,添加'group(1)'似乎会带来错误:AttributeError:'NoneType'对象没有属性'group'

有人可以帮我吗?

这是原始文件的链接:

https://raw.githubusercontent.com/irJERAD/Intro-to-Data-Science-in-Python/master/MyNotebooks/university_towns.txt