You can split the string on matches of the regular expression
^.*\bEXCLUDE\b.*\R
with global and multiline flags set.
In Ruby, for example, if the variable str
held the string
Firstly include this line
EXCLUDE this entire line
include this line
and this as single match
and EXCLUDE this line
Lastly include this line
then the method String#split could be used to produce an array containing three strings.
str.split(/^.*\bEXCLUDE\b.*\R/)
#=> ["Firstly include this line",
# "include this line\nand this as single match",
# "Lastly include this line"]
Many languages have a method or function that is comparable to Ruby's split
.
Demo
The regular expression can be broken down as follows.
^ # match the beginning of a line
.* # match zero or more characters other than line
# terminators, as many as possible
\b # match word boundary
EXCLUDE # match literal
\b # match word boundary
.* # match zero or more characters other than line
# terminators, as many as possible
\R # match line terminator