I'm trying to find a way to isolate a specific paragraph using a string as a starting point, where the string could be a word in any part of the line (not necessarily the end or the beginning).
So it will grab that entire line where the string occurs, and then it will grab until the line where it finds the secondary string. I've checked various questions and I'm not finding quite what I want. Here's an example input paragraph with the desired output paragraph:
Input:
JUNKTEXTJUNKTEXTJUNKTEXT
JUNKTEXTJUNKTEXTJUNKTEXTJUNKTEXT
NOTJUNK ABC NOTJUNK
DEF GHI JKL
MNO PQR STW
UVW XYZ NOTJUNK
JUNKTEXTJUNKTEXTJUNKTEXTJUNKTEXTJUNKTEXTJUNKTEXT
JUNKTEXTJUNKTEXT
JUNKTEXTJUNKTEXT
Objective: I want to get every LINE from ABC (including the words before ABC anf after ABC in the same line) until XYZ (including the words before and after XYZ). ABC and XYZ will always only have one occurence in the paragraph - and ABC will always occur before XYZ. My paragraphs in questions are being obtained from emails, and I'm currently using PhpMimeMailParser to parse the email.
start string search term: ABC
end string search term: XYZ
Desired Output:
NOTJUNK ABC NOTJUNK
DEF GHI JKL
MNO PQR STW
UVW XYZ NOTJUNK
Glad I could help. Here is the regex which evidently does as you prescribed:
Here is a regex tester link: regex test
Supporting info:
Options
The multi line option
mis required since the capture needs to start at the beginning of a line and not the start of the string.The single line option
sis required to ignore newlines with the dot.Explanation
So with the options as context, the expression can be described: