I need to import a large amount of building codes from a text file to a SQL database. So far I have written the following code which successfully returns the code number and title. How can I match the text after a code’s title to the beginning of the next code?
Test.txt:
101.1 Title. This is an example code.
101.1.2 Local Fees. The local jurisdiction may charge fees for building permit
violations per Section 300.1.
import re
file=open(r'C:\Test.txt','r')
text=file.read()
codes=re.findall('(\d{3,4}.[\d.]+?){1}\s([\w\s]+[.]){1}',text)
for code in codes:
print code[0],code[1]
This results in:
101.1 Title. I would like to have code[3] print ‘This is an example code.’
101.1.2 Local Fees.
Use
re.splitinstead ofre.findall. In your case: