Reputation: 8589
I have the following text block:
## 8.6.0
- **Upload date:** November 19, 2020
- **Release date:** TBC
- **Internal version:** 1171
### Feature
- dsfdsfds
- sdfdsf
- dsfdsf
### Bug fixes
- sdfsaf
- sdfsad
- sdfsdfdsf
### Internal
- sadfsdfsda
- fsdfgsadfasd
- sdfsda
## 8.5.1
- **Upload date:** November 09, 2020
- **Release date:** November 12, 2020
- **Internal version:** 1170
I would like to extract just the first entry e.g. all the text from the start of the first character in ## 8.6.0
up to just before the first character of ## 8.5.1
.
I have tried the following expression:
[#].*[0-9])(.*?)([#].*[0-9])
But it doesn't return the right result. How would I write this expression?
Upvotes: 2
Views: 128
Reputation: 769
If I've understood the problem correctly, then
^## (\d+\.?){3}.+?(?=## \d)
should work. Here's a demo.
The pattern does the following:
^## (\d+\.?){3}
.(?=## \d)
.+?
To make this work, you need the dotall
flag enabled, so .
can match newline characters.
Upvotes: 2
Reputation: 626845
Use
^##(?!#).*(?:\n(?!##(?!#)).*)*
See the regex demo.
Details
^
- start of a string (if you use it in an environment with the multiline flag enabled by default, try prepending it with (?-m)
or use ^(?<![\s\S])
)##(?!#)
- a ##
substring not followed with another #
.*
- the rest of the line(?:\n(?!##).*)*
- zero or more lines not starting with ##
not followed with another #
.Upvotes: 2