简体   繁体   中英

split string into list based on names regex python

Looking for a regex which can split the following string into list so that I can loop over and extract the values. I tried this but it didn't work.

Download the PDF file here

\b[0-9]+ [A-Za-z]+ [A-Za-z]+(.*?)\b[0-9]+ [A-Za-z]+ [A-Za-z]

Sample string

string = '''1 Acone Raffaele
^Eboli (SA) - 04/12/1971^ 148/A Dottore commercialista^ 84043 Agropoli (SA) - Via P. Mascagni, 5
^CNARFL71T04D390R^ A - Commercialisti^ Laurea in Economia e Commercio (64/S)
^Agropoli (SA) Ordine Tel. 0974824169 - Fax 0974824169 Esercente
^06/05/2002^06/05/2002^ Email: raffaeleacone@tiscali.it
^06/05/2002^Revisore legale - n. 125741^PEC: raffaele.acone@pec.commercialisti.it

2 Agresta sdfsdf dfdsf
^Salerno (SA) - 08/09/1979 269/A Dottore commercialista^ 84043 Agropoli (SA) - Via F. Angrisani, 7
^GRSDNL79P08H703B^ A - Commercialisti^ Laurea in Economia e Commercio (64/S)
^Agropoli (SA)Tel. 0974 823625 - Fax 0974 823625^ Esercente
^25/07/2012^25/07/2012^ Email: d.agresta@yahoo.it
^25/07/2012^Revisore legale - n. 165766^PEC: d.agresta@pec.it

3 Agresta Veronica
^Vallo della Lucania (SA) - 06/10/1981 281/A Dottore commercialista^ 84052 Ceraso (SA) - Via Campo, 1
^GRSVNC81R46L628Z^ A - Commercialisti^ Laurea in Economia e Commercio (LM-56)
^Ceraso (SA)^Tel. 0974 61248^Esercente
^24/01/2014^24/01/2014^ Email: veronica.ag@live.it
^24/01/2014^Revisore legale - n. 172086^PEC: veronicaagresta@pec.it

'''

Expected Output:

['1 Acone Raffaele
^Eboli (SA) - 04/12/1971^ 148/A Dottore commercialista^ 84043 Agropoli (SA) - Via P. Mascagni, 5
^CNARFL71T04D390R^ A - Commercialisti^ Laurea in Economia e Commercio (64/S)
^Agropoli (SA) Ordine Tel. 0974824169 - Fax 0974824169 Esercente
^06/05/2002^06/05/2002^ Email: raffaeleacone@tiscali.it
^06/05/2002^Revisore legale - n. 125741^PEC: raffaele.acone@pec.commercialisti.it'], 
['Agresta sdfsdf dfdsf
^Salerno (SA) - 08/09/1979 269/A Dottore commercialista^ 84043 Agropoli (SA) - Via F. Angrisani, 7
^GRSDNL79P08H703B^ A - Commercialisti^ Laurea in Economia e Commercio (64/S)
^Agropoli (SA)Tel. 0974 823625 - Fax 0974 823625^ Esercente
^25/07/2012^25/07/2012^ Email: d.agresta@yahoo.it
^25/07/2012^Revisore legale - n. 165766^PEC: d.agresta@pec.it'], 
['3 Agresta Veronica
^Vallo della Lucania (SA) - 06/10/1981 281/A Dottore commercialista^ 84052 Ceraso (SA) - Via Campo, 1
^GRSVNC81R46L628Z^ A - Commercialisti^ Laurea in Economia e Commercio (LM-56)
^Ceraso (SA)^Tel. 0974 61248^Esercente
^24/01/2014^24/01/2014^ Email: veronica.ag@live.it
^24/01/2014^Revisore legale - n. 172086^PEC: veronicaagresta@pec.it']

如果公司之间总是有一个空行,那么这可能是一个解决方案:

company_list = [ [company_string] for company_string in string.split('\n\n') if company_string is not '' ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM