• Login
Community
  • Login

Replace pattern not working correctly

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 254 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.
  • B
    Brennan OBrien
    last edited by Oct 29, 2022, 3:38 PM

    Hi again all – I was so proud of myself I was able to correctly select a block of text, but I’m not being able to do the replacement command correctly, so I’m sure my selection is wrong in some way. Here’s my starting text (and I have lots of these to do in the file):

          Derro Maniac
    

    The text is exactly 6 spaces (important, because I have other text with exactly 4 spaces I need to get rid of after I have this piece solved).

    My target outcome would look like this:

    ###
    Derro Maniac
    

    I’ve been able to successfully select the text using the following search string (regex).

    (?<=\x20{6}).*$
    

    But when I try to replace using this replace string, my original text is getting wiped out.

    ###\r\n\1
    

    I get this result:

          ###
    
    

    What am I doing wrong?

    Thanks!

    A 1 Reply Last reply Oct 29, 2022, 3:42 PM Reply Quote 0
    • A
      Alan Kilborn @Brennan OBrien
      last edited by Oct 29, 2022, 3:42 PM

      @Brennan-OBrien said in Replace pattern not working correctly:

      Try ###\r\n${0} as your replace string.

      But if you really want to know what is wrong with your replace string, I’ll tell you that you are trying to insert “group 1” (with your use of \1), but you have no group 1 captured in the find string.

      1 Reply Last reply Reply Quote 2
      • A
        Alan Kilborn
        last edited by Oct 29, 2022, 4:48 PM

        You could obtain a group one in your find string by changing it to: (?<=\x20{6})(.*)$

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