У меня есть следующий текстовый макет:
Heading
Chapter 1:1 This is text
2 This is more text
3 This is more text
4 This is more text
5 This is more text
6 This is more text
7 This is more text
8 This is more text
9 This is more text
10 This is more text
11 This is more text
12 This is more text
13 This is more text
14 This is moret text
15 This is more text
Heading
Chapter 2:1 This is text
2 This is more text...
и я пытаюсь добавить первую ссылку на главу и последнюю в этой главе сразу после заголовка, написанную в скобках. Вот так:
Heading (Chapter 1:1-15)
Chapter 1:1 This is text
2 This is more text
3 This is more text
4 This is more text
5 This is more text
6 This is more text
7 This is more text
8 This is more text
9 This is more text
10 This is more text
11 This is more text
12 This is more text
13 This is more text
14 This is moret text
15 This is more text
До сих пор я придумал это регулярное выражение:
~s/(?s)(Heading)\r(^\d*\w+\s*\d+:\d+|\d+:\d+)(.*?)(\d+)(.*?\r)(?=Heading)/\1 (\2-\4)\r\2\3\4\5/g;
но это захват первого номера сразу после главы 1: 1 (т. Е. «2», «Заголовок (глава 1: 1-2)») вместо последнего («15», как в «Заголовок (глава»). 1: 1-15) "). Может кто-нибудь сказать мне, что не так с регулярным выражением? Спасибо!