S
S
Shimpanze2018-02-15 06:30:47
JavaScript
Shimpanze, 2018-02-15 06:30:47

How to replace the number of characters in brackets with the same number of spaces?

Hello!
It is necessary to replace the found number of characters in brackets with the same number of spaces.
For example, the word "world" is found and it must be replaced with three spaces "".
How to do it? Since I'm still green, only this construction comes to mind:
.replace(/ (\w+)\b/gi, ' ??? ');

.replace(/ (\w){1}\b/gi, ' ')
.replace(/ (\w){2}\b/gi, '  ')
.replace(/ (\w){3}\b/gi, '   ')
.replace(/ (\w){4}\b/gi, '    ')
.replace(/ (\w){5}\b/gi, '     ');
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-02-15
@alshch

Could it be a little easier

mystring = "(тест)"
mystring.replace(/[^()]/g, " ")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question