Hi i have a markdow text like the one below and i want to slice it in H2 tilte, H2 content
## **Intro**
* bla bla
* bla bla bla
## Tortilla
* chico
* chica
### 1. sub-section
* and another bla.
Regex result should be :
title 1:
Intro
content 1:
* bla bla
* bla bla bla
title 2:
Tortilla
content 2:
* chico
* chica
### 1. sub-section
* and another bla.
I tried with this regex
/^## (?<title>.*)(?<content>.*(?:\n(?!##).*)*)/gm
But doesn't catch the sub-section content.
Can someone help please?
The regex below produces the output desired from the input you have given.
Explanation of most pieces:
^##\s(?<title>.*)\n(?:(?!##\s).*\n?)+The primary issue with your attempt is that you are trying to account for the new line after
titleby including it incontentwhen it just needs to be discarded.The secondary issue is that you're not providing a differentiator for lines that start with
##that are not H2 (i.e. there must be whitespace after the##)Note: the optional new line (
\n?) at the end ofcontentis required when the input does not end with a new line