import re
string = "some text \n\n\nError on the field: more\n text and lines\n\n\nError on the field: some more\n lines \n\n\nError on the field: final lines"
pieces = re.split(r'(Error on the field:)', string, re.IGNORECASE)
pieces
['some text \n\n\n', 'Error on the field:', ' more\n text and lines\n\n\n', 'Error on the field:', ' some more\n lines \n\n\nError on the field: final lines']
pieces2 = re.split(r'(Error on the field:)', pieces[4], re.IGNORECASE)
pieces2
[' some more\n lines \n\n\n', 'Error on the field:', ' final lines']
Pourquoi la troisième division du 'Error on the field:'
pas repris dans la scission initiale de pieces
, mais est ramassé quand vous divisez pieces[4]
?re.split python ne fonctionne pas pour tous les champs
Il suffit d'utiliser 're.split (r '(? I) (Erreur sur le champ :)', chaîne)' – kaza