Home > Back-end >  Get all text between each markdown heading
Get all text between each markdown heading

Time:10-29

I'm trying to extract the text between the headings in a markdown file. The markdown file will look something like this:

### Description

This is a description

### Changelog

This is my changelog

### Automated Tests added

- Test 1
- Test 2

### Acceptance Tests performed



### Blurb

Concise summary of what this PR is.

Is there anyway I can return all of the groups so that:

  • group 1 = "This is a description"
  • group 2 = "This is my changelog"

...and so on

CodePudding user response:

You can use ^[^#] . That will exclude a line that starts with #. If you want to have groups, you may use ^([^#] ).

Note that the matches include line breaks. If you don't want them, you can exclude them as well with ^([^#\n] ).

See the result

CodePudding user response:

Gets all the matches except last one.

regex match pattern:(###[\h\w\t\n.]*)((###)?\n)


check sample here
https://regex101.com/r/eBtSTM/2


  • Related