Assume I have this text
Hi there how are you. This is a test for the root cause of ice cream addiction and not the category of happiness.
I would like a regex that matches the text the starts with "root cause" and ends with either:
- the word "category";
- or a newline (whichever comes first).
I've only managed to get as far as (root cause).* but can't figure out how to add the condition for "category" or "newline".
In the above example, I expect to get back "root cause of ice cream addiction and not the".
If I then have a sentence that reads
``Hi there how are you. This is a test for the root cause of ice cream addiction
and not the category of happiness.``
(note the line break), then I expect to get back "root cause of ice cream addiction"
CodePudding user response:
You may use:
\broot cause\b.*?(?:\bcategory\b|\n)