Max Dyachenko Max Dyachenko - 1 month ago 7
Javascript Question

JS regex - how to add the spaces to the symbols that i have found using RegExp

i am looking for the symbols using this regular expression

/[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/g


I'd like to add the spaces between these symbols with both sides.
For example:
"Hello,my name is Max"


I'd like this string to look like
"Hello , my name is Max"
.

How can i do this? Thanks.

Answer

Try this:

/([-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/])/g

and replace by

 space\1space

Explanation

Comments