• Login
Community
  • Login

Regex help on multiline search & replace

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 16.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Rasiel Suarez
    last edited by Nov 1, 2015, 11:44 PM

    Hey guys, I’m pretty new to regex.

    I have many text files where I need to do search and replace but am having difficulty when the search pattern is broken up across lines. For example, let’s say we have the following:

    Debbie does indeed
    Make haste and speed
    To Dallas proceed

    And in the above I would want to make a search and replace with words that are separated by line breaks. In the above example I could do, say

    ^(Debbie does)(.+)(\r\n)(.+)(\r\n)(.+)(Dallas)(.+)$

    But this is awkward and I have to know in advance how many line breaks separate the beginning and ending targets. Checking the “matches newline” option finds one giant text block that hungrily marks nearly the whole document. What I want to do here is select the entire line where String A is then continue until finding String B and keep going til the end of that line regardless of how many line breaks separate them.

    Thanks for any help!

    1 Reply Last reply Reply Quote 0
    • S
      Scott Sumner
      last edited by Nov 2, 2015, 12:11 AM

      This should help you:

      https://notepad-plus-plus.org/community/topic/76/marking-a-large-text

      1 Reply Last reply Reply Quote 0
      • R
        Rasiel Suarez
        last edited by Nov 2, 2015, 12:42 AM

        Comes pretty close but only selects just after the first target and right before the second. I was looking to select their entire lines. How do I stick it all in a ^ and $?

        1 Reply Last reply Reply Quote 0
        • S
          Scott Sumner
          last edited by Nov 2, 2015, 12:07 PM

          In that case, maybe this one will assist:

          https://notepad-plus-plus.org/community/topic/10607/anyone-can-help-with-this-regex/4

          There should be sufficient explanation with these links to allow you to adapt them to get your desired solution.

          1 Reply Last reply Reply Quote 0
          • R
            Rasiel Suarez
            last edited by Nov 3, 2015, 2:16 AM

            Brilliant! Thank you so much Scott! :-)

            1 Reply Last reply Reply Quote 0
            • S
              Scott Sumner
              last edited by Nov 3, 2015, 12:56 PM

              True credit goes to guy038, but I’m glad I could assist.

              1 Reply Last reply Reply Quote 0
              2 out of 6
              • First post
                2/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors