Community

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

    Regex assistance in Notepad++ replacing

    Help wanted · · · – – – · · ·
    notepadd++ regex
    3
    4
    1709
    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.
    • DanailKazakov
      DanailKazakov last edited by

      When you replace stuff in notepad++ with regex, can you somehow copy over to the replace part of the text? For example in the following list:

      abcd
      123
      123
      123
      123
      cdsa
      234
      234
      234
      234

      I’d like to achieve this result:

      abcd,123,123,123,123
      cdsa,234,234,234,234

      I can select only the “\r\n” before the numbers with something like: \r\n\d+, question is, is there a way to copy over those numbers I catch with the regex to the “replace with” section.

      Or maybe use some kind of regex that looks what follows the \r\n, not quite sure how to write that though.

      1 Reply Last reply Reply Quote 0
      • cipher-1024
        cipher-1024 last edited by

        You can use a backreference in your find/replace parameters. In the find box, put parenthesis around what you want to save, and then put a “\1” in the replace box to represent the set of characters found in the parenthesis set.

        Find: \r\n(\d+?)
        Replace with: ,\1

        I’m sure someone will be able to flesh this answer out and give a better explanation, but this should get you going.

        1 Reply Last reply Reply Quote 1
        • guy038
          guy038 last edited by guy038

          Hello, @danailkazakov, @cipher-1024 and All,

          The cipher-1024’s regex S/R works fine, but I think we can even simplify it ! I propose the following S/R :

          SEARCH : \R(?=\d)

          REPLACE : ,

          • The part \R searches for any kind of EOL ( Windows, Unix or MAC form )

          • But the matching will be true, ONLY IF the EOL character(s) is(are) followed by any digit, due to positive look-ahead construction (?=\d)

          • In replacement, the EOL character(s), matching that condition, are simply changed by a comma

          Best Regards

          guy038

          1 Reply Last reply Reply Quote 3
          • DanailKazakov
            DanailKazakov last edited by

            Thanks, that worked great.

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