Community
    • Login

    Regex assistance in Notepad++ replacing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regex
    4 Posts 3 Posters 2.2k 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.
    • DanailKazakovD Offline
      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-1024C Offline
        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
        • guy038G Offline
          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
          • DanailKazakovD Offline
            DanailKazakov
            last edited by

            Thanks, that worked great.

            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