Community
    • Login

    Regex help on multiline search & replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 17.6k Views 1 Watching
    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.
    • Rasiel SuarezR Offline
      Rasiel Suarez
      last edited by

      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
      • Scott SumnerS Offline
        Scott Sumner
        last edited by

        This should help you:

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

        1 Reply Last reply Reply Quote 0
        • Rasiel SuarezR Offline
          Rasiel Suarez
          last edited by

          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
          • Scott SumnerS Offline
            Scott Sumner
            last edited by

            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
            • Rasiel SuarezR Offline
              Rasiel Suarez
              last edited by

              Brilliant! Thank you so much Scott! :-)

              1 Reply Last reply Reply Quote 0
              • Scott SumnerS Offline
                Scott Sumner
                last edited by

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

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors