Reputation: 175
I made a multiline string that looks like this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
----------
User 1 said the following:
Magna fermentum iaculis eu non diam phasellus vestibulum lorem. Lectus quam id leo in vitae turpis massa sed elementum. Ut consequat semper viverra nam libero. Libero justo laoreet sit amet cursus sit amet.
----------
User 2 said the following:
Magna fermentum iaculis eu non diam phasellus vestibulum lorem. Lectus quam id leo in vitae turpis massa sed elementum. Ut consequat semper viverra nam libero. Libero justo laoreet sit amet cursus sit amet.
What I want for regex to do is to match everything before the first set of dashes ----------
....10 dashes/hyphens to be exact.
I tried this particular regex to match to no avail.
[^-](-----){10}
Then I tried -{10}
as a clue, but it only gives me the 10 dashes/hyphens itself. I want everything before the first set of hyphens/dashes.
Upvotes: 0
Views: 75
Reputation: 163207
You could also use a capture group without a global flag to match for only a single match, and match all lines that do not start with 10 hyphens using a negative lookahead.
^(?:(?!----------).*\n)+(?=----------$)
Or you can match as least as possible lines, until you encounter a line that starts with 10 hyphens.
^(?:.*\n)+?(?=----------$)
Upvotes: 2
Reputation: 520878
You may try matching on the following pattern, with DOT ALL mode enabled:
^.*?(?=----------|$)
This will match all content up to, but including, the first set of dashes. Note that for inputs not having any dash separators, it would return all content.
If your regex engine does not support DOT ALL mode, then use this version:
^[\S\s]*?(?=----------|$)
Upvotes: 1