Extract String/Data between 2 specific words in notepad++ in multiple lines of data

前端 未结 1 1503
长情又很酷
长情又很酷 2021-01-22 04:31

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

相关标签:
1条回答
  • 2021-01-22 05:16

    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 last
    • word1 - 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.
    0 讨论(0)
提交回复
热议问题