How to add square brackets to underscores in a string with JavaScript

1 Answer

0 votes
var s = "js_js__js___js_____";

s = s.replace(/_+/g, '[$&]');

document.write(s);

/*
run:

js[_]js[__]js[___]js[_____]

*/

 



answered Jul 12, 2017 by avibootz

Related questions

...