Ooker
Ooker

Reputation: 3032

How to rearrange groups span through multiple lines?

Input

14. SEPARATION ANXIETY/265
The Continuing Saga of Zero-Gravity Elimination

Desired output

14. SEPARATION ANXIETY – The Continuing Saga of Zero-Gravity Elimination/265

My try

Find: (\d+. (.*))(/\d+\r\n)((.*))
Replace: \1–\3\2

14. SEPARATION ANXIETY–/265
SEPARATION ANXIETY

Upvotes: 1

Views: 26

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626845

It seems you are not referencing the right groups in the replacement pattern. Your (\d+. (.*))(/\d+\r\n)((.*)) pattern contains 5 capturing groups and \1 refers to the text captured with (\d+. (.*)), \3 refers to (/\d+\r\n) and \2 refers to (.*) (part of the first capturing group).

Here is a version that will do the job:

Find: ^(\d+\.\h.*)(/\d+)\R(.*)
Replace: \1 – \3\2

Details

  • ^ - start of a line
  • (\d+\.\h.*) - Group 1: 1 or more digits, a dot, a horizontal whitespace and then any 0+ chars other than line break chars as many as possible up to the last...
  • (/\d+) - Group 2: / and then 1+ digits
  • \R - a line break
  • (.*) - Group 3: the whole line.

enter image description here

Upvotes: 1

Related Questions