• Login
Community
  • Login

regex and newlines

Scheduled Pinned Locked Moved General Discussion
3 Posts 3 Posters 487 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.
  • J
    John Sampson
    last edited by Oct 27, 2022, 9:14 PM

    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.

    P T 2 Replies Last reply Oct 27, 2022, 9:19 PM Reply Quote 0
    • P
      PeterJones @John Sampson
      last edited by PeterJones Oct 27, 2022, 9:20 PM Oct 27, 2022, 9:19 PM

      @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
      • T
        Terry R @John Sampson
        last edited by Oct 27, 2022, 9:21 PM

        @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
        1 out of 3
        • First post
          1/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors