Reputation: 13
How can I create a regex expression that will match anything between given words and these two words may not be on same line.
For example: OBJECTIVES or RECEIVED--------------------------------------
-------------------------------------OFFICE SETUP or REMAINING
Upvotes: 0
Views: 71
Reputation: 2047
Assuming the words that are before and after are Objectives and Office Setup then use
(?s)(?i)(?<=(objectives)).*(?=(office setup))
This will match anything between Objectives and Office Setup regardless as to whether they are on multiple lines
(?s)
means that '.' will match new lines also allowing it to match multiline
(?i)
makes the rest of the regex case insensitive there for (objectives) will match objectives, ObJectivES etc and the same for office setup
(?<=(objectives))
Positive lookbehind for the word objectives
.*
0 or more characters
(?=(office setup))
Postive lookahead for office setup
Upvotes: 2