Community
    • Login

    regex and newlines

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 3 Posters 473 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.
    • John SampsonJ
      John Sampson
      last edited by

      I wanted to rename a number of files using a batch file in a command-line app. To begin, I wanted to change each line to “ren \1 \1” so that I could work on it. However, Notepad++ included newlines so that it changed each line to “ren \1” on one line, “\1” on a new line. I could not work out how to prevent this, so I tried the same procedure in Sublime Text where it worked as I wanted it to work.

      PeterJonesP Terry RT 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @John Sampson
        last edited by PeterJones

        @John-Sampson ,

        I believe that capture group 1 included the newline. Since you only showed us your REPLACE, without showing the FIND, I cannot show you specifically what’s wrong with your FIND that puts the newline in group 1

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • FAQ: Where to find regular expressions (regex) documentation
        • Notepad++ Online User Manual: Searching/Regex
        1 Reply Last reply Reply Quote 3
        • Terry RT
          Terry R @John Sampson
          last edited by

          @John-Sampson said in regex and newlines:

          However, Notepad++ included newlines so that it changed each line to “ren \1” on one line, “\1” on a new line

          So if you were using \1 that assumes you were searching in regular expression mode. Then I’m going to assume your find what field also captured the CR and LF characters which are EOL markers. Returning those would likely produce the result you saw.

          I think you need to post the Find What field you used so we can confirm what you were doing.

          Oh, just saw that @peterjones also believes the same.

          Terry

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