У меня есть следующая строка:
It reported the proportion of the edits made from America was 51% for the Wikipedia, and 25% for the simple Wikipedia.[142] The Wikimedia Foundation hopes to increase the number in the Global South to 37% by 2015.[143]
Я пытаюсь заменить все символы, подобные этому .[xxx]
, на .[xxx] \n
;
х здесь цифры
Я получаю помощь от разных ответов о переполнении стебля; один такой:
Python вставляет разрыв строки в строке после символа "X"
Регулярное выражение: соответствует полной остановке и одному слову в питоне
import re
str = "It reported the proportion of the edits made from America was 51%
for the Wikipedia, and 25% for the simple Wikipedia.[142] The Wikimedia
Foundation hopes to increase the number in the Global South to 37% by
2015.[143] "
x = re.sub("\.\[[0-9]{2,5}\]\s", "\.\[[0-9]{2,5}\]\s\n",str)
print(x)
Ожидаю следующий вывод:
It reported the proportion of the edits made from America was 51% for the Wikipedia, and 25% for the simple Wikipedia.[142]
The Wikimedia Foundation hopes to increase the number in the Global South to 37% by 2015.[143]”
Но я получаю:
It reported the proportion of the edits made from America was 51% for the Wikipedia, and 25% for the simple Wikipedia\\.\[[0-9]{2,5}\]\s The Wikimedia Foundation hopes to increase the number in the Global South to 37% by 2015\\.\[[0-9]{2,5}\]\s