I have in javascript a text like
some text
- list
- list
- list
more text
- another list
- another list
- another list
How can I match all the lines that starts with the character -
until a line doesn't start with that character?
For example, given the text above I need to match the two groups
- list
- list
- list
and
- another list
- another list
- another list
I tried with the regex /^(-.*\n-.*|$)/gm
, but works only if the list contains an even number of elements, while I need it to work for an arbitrary number of elements.
Currently you only match 2 times a hyphen (an even number) and you are not repeating that match.
You could match a single line starting with a hyphen, and then optionally repeat following lines staring with a newline and a hyphen.
^-.*(?:\n-.*)*
A bit more extensive pattern making use of a capture group:
^[^-\s].*\n(-\s+[^\s-].*(?:\n-\s+[^\s-].*)*)
The pattern matches:
-
-
as a value for every item