In this text, I'm trying to extract all of the titles and page numbers of lines that:
- Begin with -
- Followed by whitespace
- Then a chapter title
- Then the page #, like so: #page=9&
Here's an example of the raw text I'm working with:
| "Principles of Microeconomics 2e" (null)
- "Preface" #page=9&zoom=0,0,58
| "1. About OpenStax" #page=9&zoom=0,0,150
| "2. About OpenStax resources" #page=9&zoom=0,0,248
| "3. About Principles of Microeconomics 2e" #page=9&zoom=0,0,544
| "4. Additional resources" #page=13&zoom=0,0,367
| "5. About the authors" #page=14&zoom=0,0,58
- "Chapter 1. Welcome to Economics!" #page=17&zoom=0,0,58
| "1.1. What Is Economics, and Why Is It Important?*" #page=18&zoom=0,0,338
| "1.2. Microeconomics and Macroeconomics*" #page=22&zoom=0,0,448
| "1.3. How Economists Use Theories and Models to Understand Economic Issues*" #page=23&zoom=0,0,565
My current regex:
(?:\-\s)(["'])(?:(?=(\\?))\2.)*?(?:page=)(?<=\=)(.*?)(?=\&)
Currently using this regex matches the entire line, but doesn't put the desired elements into seperates groups.. And I'm having trouble doing this seperation.
current output: current output
desired output:
Match 1: "Preface" #page=9&
Group 1: Preface
Group 2: 9
Match 2: "Chapter 1. Welcome to Economics!" #page=17&
Group 1: Chapter 1. Welcome to Economics!
Group 2: 17
I am trying to extract the title in one group, and the page number in another. How can I do this?