Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Regex help on multiline search & replace

    Help wanted · · · – – – · · ·
    2
    6
    15876
    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 Suarez
      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 Sumner
        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 Suarez
          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 Sumner
            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 Suarez
              Rasiel Suarez last edited by

              Brilliant! Thank you so much Scott! :-)

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

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors