All,
I have been trying to extract the text between 2 specific words in Notepad++ using RegEx Search and Replace, but with no luck,
It gives me the last match f
You need to make the . inside the capturing group match any character including a newline:
.*word1((?s:.*?))Word2.*
^^^^^^^^
The (?s:...) modifier group with a DOTALL flag turned on will make the . match any chars including line breaks. The . matches newline must be OFF (see screenshot below). To make the pattern work irrespective of the . matches newline option, use the modifier groups with each . inside the pattern: (?-s:.*)word1((?s:.*?))Word2(?-s:.*) (where (?-s:...) turns the DOTALL behavior inside the modifier group).
An equivalent of the (?s:.*?) pattern is [\s\S]*? ([\w\W]*?, [\d\D]*?) but using the modifiers seems a more native way of solving this issue.
Pattern details:
.* - any chars other than line break chars, as many as possible, up to the lastword1 - word1 on a line((?s:.*?)) - Group 1 matching any 0+ chars, as few as possible up to the first...Word2 - Word2 substring and.* - the rest of the line.