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']
爲什麼的'Error on the field:'
第三裂在pieces
初始分裂沒有回升,但回升的時候你拆pieces[4]
?蟒蛇re.split不工作的所有領域
只要使用're.split(r'(?i)(錯誤在字段:)',字符串)' – kaza