Community
    • Login

    replace character with multiple spaces

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    search & replaceregex
    8 Posts 5 Posters 762 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.
    • black_catB
      black_cat
      last edited by black_cat

      Hi,

      can someone tell me, where my brain has decided to go on holiday regarding the replacment regex in notepad serach/replace

      i have a string ex. “ad” and i want to replce that string with a number of spaces say 20.

      my idea:
      c30ba6b8-4499-48b4-95f9-8b8601346434-image.png .

      my result:
      019d0db5-6a66-42c9-9d19-0596f21050d9-image.png

      I have found nothing so far that says this should not work.

      I’d be glad for any news even if it’s just, that np++ does not work like that ;)

      P.S.: Notepad Version V 8.4.8 64bit

      Alan KilbornA Mark OlsonM wonkawillyW 3 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @black_cat
        last edited by Alan Kilborn

        @black_cat said in replace character with multiple spaces:

        I’d be glad for any news even if it’s just, that np++ does not work like that ;)

        np++ does not work like that

        1 Reply Last reply Reply Quote 2
        • Mark OlsonM
          Mark Olson @black_cat
          last edited by

          @black_cat
          Consult the regex documentation.

          The basic issue is that while there is special syntax for replacements, it is different from the searching syntax. This is true of all regex engines For example, \x20{20} (I used \x20 for the space character) matches 20 spaces when searching, but the only way to insert 20 spaces in a replacement is \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20

          1 Reply Last reply Reply Quote 2
          • black_catB
            black_cat
            last edited by

            Thanke you guys for the info, now I at least know that it’s just not possible.

            Has anyone a workaround or an alternitive?

            Mark OlsonM Alan KilbornA 2 Replies Last reply Reply Quote 0
            • Mark OlsonM
              Mark Olson @black_cat
              last edited by

              @black_cat
              It is possible, just not the way you thought. see my first response.

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @black_cat
                last edited by

                @black_cat

                If you want to implement your own replacement syntax, you can do so with scripting; some hints are in the FAQ HERE.

                1 Reply Last reply Reply Quote 3
                • wonkawillyW
                  wonkawilly @black_cat
                  last edited by wonkawilly

                  @black_cat
                  I’m afraid that the Npp Search and Replace dialog can’t use the regex you typed into the Replace textbox but only into the Search textbox.

                  This is because in case of using regex, the replace part of the Find and Replace function is interpreted in a different manner than the find part: the {20} part is in fact interpreted literally, as a normal text string.

                  But a possible solution is to use Python script (you must have already installed the relative plugin) than you have to open its console and type the following command into its command line;

                  editor.rereplace('ad', ' ' * 20)
                  

                  that instruct Python to fined “ad” and replace it with 20 spaces. Than hit run. You should obtain your wished result.

                  Another valid alternative of course is to actually type 20 spaces into the Replace textbox.

                  1 Reply Last reply Reply Quote 3
                  • guy038G
                    guy038
                    last edited by guy038

                    Hi, @black_cat, @alan-kilborn, @mark-olson, @wonkawilly and All,

                    And here is on other way to achieve your goal, @black_cat !


                    • In your current working tab or in a new tab, type in the following string, on a new line
                    (                    )
                    
                    • To verify if you get the right number of spaces, just double-click inside the parentheses gap

                    • Select all this line, with the two parentheses

                    • Hit the Ctrl + H shortcut ( Replace dialog )

                    => The Find what: zone should be populated with that string

                    • Click on the small button, with the two UP and DOWN arrows, close to the Find and Replace zones
                    => The (                    ) string should have moved to the REPLACE zone !
                    
                    • Then, type in ad in the Find what: zone

                    • Select the Regular expression search mode    ( IMPORTANT )

                    And… enjoy ;-))


                    In the replacement part, you may, as well, use a composite text like, for instance :

                    (   This is                    a test !   )
                    

                    Best Regards,

                    guy038

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