replace character with multiple spaces
-
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:
.my result:
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
-
@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
-
@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
-
Thanke you guys for the info, now I at least know that it’s just not possible.
Has anyone a workaround or an alternitive?
-
@black_cat
It is possible, just not the way you thought. see my first response. -
If you want to implement your own replacement syntax, you can do so with scripting; some hints are in the FAQ HERE.
-
@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.
-
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
andDOWN
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