• Login
Community
  • Login

Regex assistance in Notepad++ replacing

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
regex
4 Posts 3 Posters 2.0k 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.
  • D
    DanailKazakov
    last edited by Oct 10, 2017, 1:09 PM

    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
    • C
      cipher-1024
      last edited by Oct 10, 2017, 4:26 PM

      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
      • G
        guy038
        last edited by guy038 Oct 10, 2017, 7:00 PM Oct 10, 2017, 6:59 PM

        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
        • D
          DanailKazakov
          last edited by Oct 16, 2017, 12:39 PM

          Thanks, that worked great.

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