Search code examples
regexnotepad++notepadprogrammers-notepad

[Auto Select Text Between two given words in a notepad++]


I have a large text files.I have a given specific keyword [with spaces in between like "ABC DEF G"]. It either occurs in the text file exactly two times or does not occur at all.

I want to have a notepad++ search such that all the text between these two keywords (around 300 to 1000 lines) gets selected automatically. I will then do some operation on this selected text via my plugin.So my first question is:

Is this autos-election possible(via regular expression or some already built plugin).

If yes ,can some one please suggest.

As of now I am reading entire text file to search which is time and memory consuming. Thanks.


Solution

  • Try this Regex:

    (?<=ABC DEF G)[\s\S]*(?=ABC DEF G)

    Click for Demo

    Explanation:

    • (?<=ABC DEF G) - Positive Lookbehind to find the position which is preceded by the text ABC DEF G
    • [\s\S]* - matches 0+ occurrences of any character
    • (?=ABC DEF G) - Positive lookahead to find the position immediately followed by the text ABC DEF G

    Output:

    enter image description here